Creating variables from dicts
MRAB
python at mrabarnett.plus.com
Tue Feb 23 16:31:48 EST 2010
vsoler wrote:
> Hi,
>
> I have two dicts
>
> n={'a', 'm', 'p'}
> v={1,3,7}
>
Those aren't dicts, they're sets.
> and I'd like to have
>
> a=1
> m=3
> p=7
>
> that is, creating some variables.
>
> How can I do this?
The real question is not how, but why?
Anyway, assuming you want them to be global variables:
globals().update(dict(zip(n, v)))
On my machine the variables didn't get the correct values because, as I
said, 'n' and 'v' are sets, so the order of the members is arbitrary.
More information about the Python-list
mailing list