why for loop print only once after add if statement
Sayth Renshaw
flebber.crue at gmail.com
Sat May 28 06:49:59 EDT 2016
On Saturday, 28 May 2016 20:19:23 UTC+10, meInvent bbird wrote:
> for item, i in enumerate(aa)
> print item
>
> this writing, it can print all values
>
> for item, i in enumerate(aa)
> if item == findit:
> print item
>
> this only print the first value, means it only print once then not print again,
>
> where is wrong?
Enumerate is there to get rid of the i its not need enumerate is a generator.
list(enumerate(aa, start=1))
https://docs.python.org/3/library/functions.html#enumerate
In [1]: aa = range(10)
In [2]: list(enumerate(aa, start=1))
Out[2]:
[(1, 0),
(2, 1),
(3, 2),
(4, 3),
(5, 4),
(6, 5),
(7, 6),
(8, 7),
(9, 8),
(10, 9)]
Sayth
More information about the Python-list
mailing list