NEW TO THIS: Assigning values to strings in list?

Justin Shaw wyojustin at hotmail.com
Sat Jul 20 00:48:11 EDT 2002


> Basicely I have two lists, one containing the future string-names
> and one containing the values I want to give them. The order is
> identical in both. Right now I'm solving this by a dictionary, but
> I would really prefer to have straight strings as a result of my
> operation.

I like the idea of keeping your namespace clean.  But if what you really
want is to assign the values to your local namespace I have two solutions.

1. Ugly one-liner
eval ';'.join(['='.join(x) for x in zip(names, [str(v) for v in values])])

2. Update locals()
locals().update(dict(zip(names,values)))

> Thanks, Joh
You bet
Justin





More information about the Python-list mailing list