0

Is countdown (), сreated 3 lists, because of cycle "for"'?

def countdown(i): while i > 0: yield i i -= 1 for i in countdown(3): print(list(countdown(3))) output : [3, 2, 1] [3, 2, 1] [3, 2, 1] =================== def countdown(i): while i > 0: yield i i -= 1 for i in countdown(3): print(list(countdown(i))) output : [3, 2, 1] [2, 1] [1]

1st May 2019, 7:08 PM
Магомед Акуев
Магомед Акуев - avatar
1 Resposta
+ 2
In for statement you shouldn't write countdown(i) cause it executes this method again so this is why you're getting that output. In for statement just write print(i)
1st May 2019, 8:10 PM
Matiu
Matiu - avatar