Message216938
Python 2.7.6: Affected
Python 3.2.3: Not affected
dict() allows keyword expansion using a dict() with integer keys, whereas attempting to do so with most other functions raises a TypeError with the message, "keywords must be strings". The same thing happens with collections.defaultdict(), but not collections.Counter() or collections.OrderedDict, presumably because they override dict.__init__().
>>> old_dict = {'a': 1, 2: 'b'}
>>> old_dict
{'a': 1, 2: 'b'}
>>> other_dict = {'c': 3, 4: 'd'}
>>> other_dict
>>> new_dict = dict(old_dict, **other_dict)
>>> new_dict
{'a': 1, 2: 'b', 4: 'd', 'c': 3}
I feel like this must be known, but I didn't find anything with a search. |
|
Date |
User |
Action |
Args |
2014-04-21 11:54:59 | Cyphase | set | recipients:
+ Cyphase |
2014-04-21 11:54:59 | Cyphase | set | messageid: <1398081299.38.0.288058317096.issue21320@psf.upfronthosting.co.za> |
2014-04-21 11:54:59 | Cyphase | link | issue21320 messages |
2014-04-21 11:54:58 | Cyphase | create | |
|