modifying values of List or Dictionary when iterating on them

2007-05-24 Thread aspineux
Hello I just want to update the data inside List or Dictionary without adding or deleting object. is this correct ? l=[1, 2, 3] for i, v in enumerate(l): l[i]=v+1 d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 Both works, but : are they correct ? are they optimum for

Re: modifying values of List or Dictionary when iterating on them

2007-05-24 Thread Christopher Anderson
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. -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying values of List or Dictionary when iterating on them

2007-05-24 Thread aspineux
On 24 mai, 19:21, Christopher Anderson [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list