assigning values to array element
Paul Rubin
http
Tue Oct 14 23:13:31 EDT 2003
crescent_au at yahoo.com (Ben) writes:
> This may sound easy but I'm having trouble assigning values to array
> element. My problem is as follows:
>
> m = ['Peter', 'Sam', 'Dave', 'Carl']
> for o in m:
> # Here first o is 'Peter'.. I want to do something like this:
> Peter = 10
>
> # if i do %s %o = 10, it gives me error...
>
> How can I do it?
Um, you probably really don't want to do that. See the docs about
how Python dictionaries work. Then try something like:
m = ['Peter', 'Sam', 'Dave', 'Carl']
table = {} # note these are curly braces
for o in m:
table[o] = 10
More information about the Python-list
mailing list