[Python-ideas] Unpacking a dict
Eric V. Smith
eric at trueblade.com
Wed May 25 17:01:56 EDT 2016
On 5/25/2016 4:14 PM, Ethan Furman wrote:
> On 05/25/2016 01:08 PM, Eric V. Smith wrote:
>> x, y = extract(mapping, 'a', 'b')
>> print(x, y)
>> 1, 2
>
> Let's pretend you wrote:
>
> a, b = extract(mapping, 'a', 'b')
>
> since that's the way I would almost always be using it.
>
> The proposal is this:
>
> a, b = **mapping
>
> The advantages:
>
> - much more readable
> - less duplication
>
> Less duplication might not seem like that big a deal, but it's one of
> the motivators behind decorations and in-place operators, which are both
> wins.
I agree that would be a win. That's a lot of compiler magic, though.
Eric.
More information about the Python-ideas
mailing list