I have strange issue when deleting element of list which I'm browsing. Here is the code , please have a look.
-
>>> li = ['mike','anil','jassi']
-
>>> for name in li:
-
print name
-
-
mike
-
anil
-
jassi
-
>>> for name in li:
-
print name
-
li.remove(name)
-
-
mike
-
jassi
-
>>> li
-
['anil']
-
It seems strange, In my project , I have global list , while going thro' each item , I have to delete item upon certain condition. But I'm not getting result as expected whenever it delete element. It seems as upon deletion, List length get decreased and it is causing this behavior (might be As Designed from python or I can use list as this way)
If someone know details behind this behavior of list , pls share (However I got workaround for this issue by using another list and putting element and then deleting 1 by 1 :))
thanks,
Anil