[Tutor] variables into a dictionary

alan.gauld@bt.com alan.gauld@bt.com
Thu, 10 Oct 2002 14:20:20 +0100


> hello pythoners,
> i have some variables here:
> one = 1
> three = 4
> six = 6
> 
> how can i assign those vars into a dictionary
> numbers={'one':one,'three':three,'six':six}

Erm, I'm not sure what you mean. The line above does assign 
them to a dictionary!

Do you mean one by one? Like;

numbers['one'] = one

Or do you mean assign values to the dictionary instead of 
variables? If so thats what you are doing.

print numbers['one'] #--> prints 1

If not can you expand a little on what you want?

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld