properly delete item during "for item in..."
Ratko
rjagodic at gmail.com
Thu Jul 17 15:32:00 EDT 2008
> > For dictionaries we can just iterate over values() or items() as
> > opposed to itervalues() or iteritems() since that's technically a copy
> > of values or items in the dict, right?
>
> No! In fact the whole point of iteritems and itervalues and iterkeys is
> that they *DO NOT* make copies, so changing the dictionary out from
> under them is a programming error.
>
> If you use dict.items(), dict.keys() or dict.values(), then you're OK,
> because these methods *do* create new lists for both.
That's what I meant, it just didn't come across correctly I guess.
Thanks for clarifying these issues. I think I have a better
understanding now.
R
More information about the Python-list
mailing list