Aug-30-2019, 05:20 AM
It's usually dangerous to mutate the list while iterating over it. But if you know what are you doing then...
Simple code to remove elements in place (starting from end in order not to mess indices):
Simple code to remove elements in place (starting from end in order not to mess indices):
>>> test = [None, 'b', None, 'a', None] >>> for i in range(len(test) - 1, -1, -1): ... if test[i] == None: ... del test[i] ... >>> test ['b', 'a']
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.