Python What is difference between file iterator and list iterator? -


this question has answer here:

if have file iterator

with open('test1.txt','r') f1:  print(f1.__next__()) 

but if same thing list, doesn't work.

a1 = [1,2,3,4,5] a1.__next__() 

so, difference between file iterator , list iterator? file , list (or tuple, dictionary, etc.) iterators behave differently?

there no such file iterator , list iterator.iterator works on iter objects. list iterable , not iter object, can make them iterable.

a =[1,2,3,4,5] a= iter(a) a.next() 

all python data types except number can made iterable.

confused python lists: or not iterators?


Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -