use of index (beginner's question)

Rusty Scalf iai-gis at sonic.net
Wed Apr 27 20:42:30 EDT 2011


Greetings,
I am just now learning python and am trying to use the index function 
with variables.
list1 = ['pig', 'horse', 'moose']
list2 = ['62327', '49123', '79115']
a = list2[list1.index('horse')]
print a
 >49123
 -works fine. But
list1 = ['pig', 'horse', 'moose']
list2 = ['62327', '49123', '79115']
n = 2
s2 = "list" + `n`
a = s2[list1.index('horse')]
print a
 -does not work
I'd like to use the index function in a loop updating the file names by 
adding a number to that name with each cycle. But can't get to first base.
Thank you,
 Rusty Scalf


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /