Dnia 10-12-2010 o 20:14:30 Alex Hall <mehg...@gmail.com> napisał(a):

Hi all,
I was googling a way to do something like
mydict=mydict.extend(additionaldict)

and someone on a forum recommends this:
mydict=dict(mydict, **additionaldict)
What is the ** doing here?


As far as I know the ** indicates that the argument passed (here named: additionaldict) is a dictionary. One * would mean that it is a tuple.

I'm not sure but it seams to me that the usual way to *update* a dictionary with the contents of an other dictionary is to use the .update dictionary method.

Examples:

animals= {'cat': 'Bobo', 'dog': 'Rex'}
animals2= {'cow': 'some name that I can\'t think of right now', 'bird': 'Falco'}
animals.update(animals2)
print animals
{'bird': 'Falco', 'dog': 'Rex', 'cow': "some name that I can't think of right now", 'cat': 'Bobo'}
print animals2
{'bird': 'Falco', 'cow': "some name that I can't think of right now"}


Hope my answers are right and it helps,

Piotr
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to