modifying values of List or Dictionary when iterating on them

A

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=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 big structure ?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top