I am removing elements from a list. But using for
to iterate through the elements , I can see that alternate elements are being accessed, hence all elements are not getting deleted.
Code
l = ['A','B','C','D','E','F']
for x in l:
l.remove(x)
print "My List:"+str(l)
print "Final List:"+str(l)
Output
My List:['B', 'C', 'D', 'E', 'F']
My List:['B', 'D', 'E', 'F']
My List:['B', 'D', 'F']
Final List:['B', 'D', 'F']
Can you please suugest any modification in this logic which would sort the issue. Alternatively if there is a better approach to this.