Time exceeded error in using cycle

from itertools import cycle for char in cycle("string"): A = [] A.append(char) print(char) if len(A) == 7: break I wanted to print out s t r i n g s but it didn't work and time exceeded error occurred. What is the problem of this code?

8/31/2016 6:56:03 PM

Solid State

2 Answers

New Answer


You should initialize A before the loop, otherwise it will never get length of 7.


Thanks a lot. Now I realize that A is iteratively reassigned to an empty list.