is this pythonic?
alex23
wuwei23 at gmail.com
Wed Jan 21 13:12:39 EST 2009
On Jan 22, 3:56 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> 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)'.
Ack, you're absolutely correct.
TP: my mistake, the for loop won't work at all. I'd really recommend
using the dictionary-based solution.
Apologies all around.
More information about the Python-list
mailing list