modifying values of List or Dictionary when iterating on them

Christopher Anderson sidewinder.asu at gmail.com
Thu May 24 13:21:41 EDT 2007


> 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.



More information about the Python-list mailing list