fork download
  1. from itertools import count
  2.  
  3. class CycleView:
  4. def __init__(self, seq):
  5. self.seq = seq
  6.  
  7. def __getitem__(self, index):
  8. if isinstance(index, slice):
  9. return map(
  10. self.__getitem__,
  11. count(index.start) if index.stop is None
  12. else range(index.start or 0, index.stop)
  13. )
  14. return self.seq[index % len(self.seq)]
  15.  
  16. DEADVUL = 'x', 'y', 'z'
  17. print(*CycleView(DEADVUL)[:10])
  18. print(*CycleView(DEADVUL)[2000000000:2000000010])
Success #stdin #stdout 0.03s 9568KB
stdin
Standard input is empty
stdout
x y z x y z x y z x
z x y z x y z x y z