dict.fromkeys strange behavior

Tsviki Hirsh tsviki.hirsh at gmail.com
Mon Dec 7 03:42:47 EST 2009


Dear list,

I'm trying to create a dictionary from set of keys and values using
dict.fromkeys
When I type:

>>>dict.fromkeys('a',50)

the output is:

{'a': 50}

This is fine, but when I try to set the same value to a different name key:

>>>dict.fromkeys('at',50)

the output now is:

{'a': 50, 't': 50}

This is obviously not what I wanted.

What are the alternatives?

Thanks a lot
Tsviki Hirsh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091207/5946353d/attachment.html>


More information about the Python-list mailing list