[Python-Dev] Very Strange Argument Handling Behavior
Xavier Morel
python-dev at masklinn.net
Sat Apr 17 12:53:34 CEST 2010
On 16 Apr 2010, at 23:31 , Guido van Rossum wrote:
>
> +1.
>
> Apparently dict(x, **y) is going around as "cool hack" for "call
> x.update(y) and return x". Personally I find it more despicable than
> cool.
This description doesn't make sense since `dict(x, **y)` returns not
an updated `x` but a new dictionary merging `x` and `y`.
And that's how (and why) I use it, it's simpler (and — I believe — more
readable) to write `z = dict(x, **y)` than `z = dict(x); z.update(y)`,
since Python doesn't overload addition as it does for lists:
l3 = l1 + l2
works and is equivalent to
l3 = list(l1); l3.extend(l2)
but there is no easy way to say that with dicts, at the moment.
More information about the Python-Dev
mailing list