Sep-28-2020, 02:40 PM
(Sep-28-2020, 09:17 AM)buran Wrote: @perfingo - you will be surprised what the result of your code is when the order of elements is different. Don't change list while iterating over it
/.../
it will work if you iterate over copy of the original list though
assigning list comprehension to old_list is solving OP of removing elements and keeping the same variable
Mea culpa! What was I thinking? Through my lapse of attention I gave really bad advice and committed real sin (fortunately no puppies died). As smart people had said:
"If fact, in any programming language for most part if you mutate something while you iterating over it you living in state of sin and you deserve whatever happens to you" -- Raymond Hettinger, Python core-developer, Transforming Code into Beautiful, Idiomatic Python
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.