Python What is difference between file iterator and list iterator? -
this question has answer here:
- confused python lists: or not iterators? 4 answers
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.
Comments
Post a Comment