dict.fromkeys strange behavior

2009-12-07 Thread Tsviki Hirsh
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}

Re: dict.fromkeys strange behavior

2009-12-07 Thread Chris Rebert
On Mon, Dec 7, 2009 at 12:42 AM, Tsviki Hirsh tsviki.hi...@gmail.com wrote: 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

Re: dict.fromkeys strange behavior

2009-12-07 Thread Terry Reedy
Tsviki Hirsh wrote: dict.fromkeys('at',50) {'a': 50, 't': 50} This is obviously not what I wanted. Not obvious at all. It is precisely what you asked for ;-) Please read the doc: 5.8. Mapping Types — dict classmethod fromkeys(seq[, value]) Create a new dictionary with keys from seq and