[Tutor] create 1000 000 variables
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Sun Jul 16 17:08:11 CEST 2006
>> > In fact I want to create a list of variables from the list of strings
>> >
>> > Example: ['var1', 'var2', 'var3'....] - list of strings
>>
>> Do you know about "dictionaries" yet?
> Yes. I know about dictionaries.
Hello,
Can you show us an example of the kind of dictionary usage you've used
before?
I'm skirting really indirectly on this one, because I'm still not sure
where the difficulty is in applying dictionaries to this problem. Just to
hint at this: the dictionary my_vars shown below:
###########################
my_vars = {}
my_vars['v1'] = 'tesuji'
my_vars['v2'] = ['anti-suji']
my_vars['v3'] = {'atari' : 1 }
###########################
is one that directs string names 'v1', 'v2', and 'v3' to some arbitrary
values. We can later look things up in the dictionary by providing the
name of the key:
##############################
print "I'm reading James Davies' %s" % my_vars['v1']
print "I don't yet have %s" % my_vars['v2'][0]
print "%s!" % my_vars['v3'].keys()[0]
##############################
More information about the Tutor
mailing list