NameError when assigning dictionary values

lewst lewst at yahoo.com
Mon Apr 3 00:03:51 CEST 2000


Gordon McMillan <gmcm at hypernet.com> wrote:

> >   # add each key-value pair to the dictionary and
> >   # then for each value, create an empty list.
> >   mydict = {}                         
> >   for key,value in [ (".", "one"), ("+", "two") ]:
> >       mydict[key] = value
> >       value = []
> >   print mydict
> >   print one,two
> > 
> > Whe I run this I get "NameError: one".  Why aren't my 2 empty lists
> > named "one" and "two" being created?
> 
> You're creating two empty lists, both named "value".The first 
> is thown away by creating the second. Nowhere are "one" and 
> "two" variable names, hence the NameError. 

Ok.  So now how do I get the program to do what I want?


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com




More information about the Python-list mailing list