is this pythonic?
MRAB
google at mrabarnett.plus.com
Wed Jan 21 12:56:59 EST 2009
alex23 wrote:
> On Jan 22, 3:27 am, MRAB <goo... at mrabarnett.plus.com> wrote:
>> FYI, you shouldn't modify a list you're iterating over.
>
> But I'm not. I'm building a new list and binding it to the same name
> as the original, which works perfectly fine (unless I'm missing
> something):
>
[snip]
I was referring to the code:
for index, record in enumerate(l):
if record['title'] == 'ti':
l.pop(index)
where you are enumerating and iterating over 'l', but also modifying 'l'
with 'l.pop(index)'.
More information about the Python-list
mailing list