Why is iter() needed here? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Why is iter() needed here?

code: l = [1, 2, 3, 4] l = iter(l) for i in l: print(i, next(l)) Why do you have to call iter() when the for loop already has done that?

11th Feb 2019, 4:27 PM
Juho Pesonen
Juho Pesonen - avatar
2 ответов
+ 9
For behind the scenes use iter so in that scenario in one loop you process two values.
11th Feb 2019, 4:55 PM
Hubert Dudek
Hubert Dudek - avatar
+ 4
For fun ;-)
11th Feb 2019, 4:51 PM
Hubert Dudek
Hubert Dudek - avatar