[Tutor] assigning values to dictionary

Steve Willoughby steve at alchemy.com
Fri Oct 3 19:39:37 CEST 2008


On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
> I have a list of dictionary values that i am looping through that upon
> each iteration I would like to assign these values to a new dictionary
> name. 
> 
> For example...
> 
> item=0
> for line in some_dict:
> 	## some how assign dict values to new name
> 	"new_dict_name_"+item = line

You could use eval, I suppose, but are you sure that 
making up new dictionary names on the fly like that is
the solution that best fits the problem as opposed to
having, say, a set of objects or an overall dictionary
of dictionaries you add to?  What's the bigger context
this fits into?  Although you *can* do this sort of thing,
it quite often ends up not being the most elegant thing
to do.

-- 
Steve Willoughby    |  Using billion-dollar satellites
steve at alchemy.com   |  to hunt for Tupperware.


More information about the Tutor mailing list