faqts : Computers : Programming : Languages : Python : Common Problems : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 5 people (60%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

How to assign values to list elements? eg, m = ['aa','bb','cc'] I want to do- for o in m: aa=5

Feb 15th, 2004 09:32
Washington Corrêa, ben ben,


Do you mean creating new objects from list elements? If yes, then I
think this might help:
mm = ['aa', 'bb', 'cc']
for o in mm:
    exec o + "=12"
print aa
print bb
print cc
This code will create three int objects (aa, bb and cc), all with value 12.
ok?