How to make a copy of chained dicts effectively and nicely?

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Tue Sep 27 18:27:25 EDT 2016


On Wednesday, September 28, 2016 at 2:27:36 AM UTC+13, Jussi Piitulainen wrote:
> Lawrence D’Oliveiro writes:
>> dict(dict(d1, **d2), **d3)
> 
> Nice expression. But that's not available if the keys are not strings:
> 
> dict({}, **{ 1:3 })
> ==>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: keyword arguments must be strings
> 
> On the other hand, '1' seemed to work (in Python 3.4.3) as key, though 1
> cannot possibly be a keyword parameter in a function definition :)

Pity. I wonder why it bothers to check?



More information about the Python-list mailing list