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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -