im teaching my self python and i came across this interesting question which says:
Implement a generator cycle such that if we assign i = cycle() then repeated calls to next(i) return the values me myself i me myself i ...
I can't use a for loop but only a generator or stream. I cant use libraries. I need to output it 20 times
what I've tried so far but i cant manage to get the cycle to work:
def cycle(i):
saved = []
for el in m:
yield el
saved.append(el)
while saved:
for el in saved:
yield element
for el in m
: where didm
come from? change it intoi
and it should work fine :Pm
should bei
as that is the list you are iterating through. Another question, why append the list to another list before iterating through it?