+ 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?

31st Aug 2016, 6:56 PM
Eunjae Lee
Eunjae Lee - avatar
2 Respostas
+ 1
You should initialize A before the loop, otherwise it will never get length of 7.
31st Aug 2016, 9:45 PM
Guilherme Passero
Guilherme Passero - avatar
0
Thanks a lot. Now I realize that A is iteratively reassigned to an empty list.
1st Sep 2016, 8:02 AM
Eunjae Lee
Eunjae Lee - avatar