+ 1
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?
2 Antworten
+ 1
You should initialize A before the loop, otherwise it will never get length of 7.
0
Thanks a lot. Now I realize that A is iteratively reassigned to an empty list.