modifying values of List or Dictionary when iterating on them

aspineux aspineux at gmail.com
Thu May 24 15:20:35 EDT 2007


On 24 mai, 19:21, "Christopher Anderson" <sidewinder.... at gmail.com>
wrote:
> > d=dict(a=1, b=2, c=3)
> > for k, v in d.iteritems():
> >     d[k]=d[k]+1
>
> You might as well do: d[k] = v + 1, like for the list.


ops, yes it was a typo




More information about the Python-list mailing list