[Python-ideas] Unpacking a dict

Paul Moore p.f.moore at gmail.com
Thu May 26 16:18:14 EDT 2016

On 26 May 2016 at 20:48, MRAB <python at mrabarnett.plus.com> wrote:
> On 2016-05-26 20:25, Paul Moore wrote:
> [snip]
>> Personally, though, I don't see *that* much wrong with
>>     partner_id = values['partner_id']
>>     product_id = values['product_id']
>>     ship_to = values['ship_to']
>>     product_ids = values['product_ids']
>> It's a bit repetitive, and maybe a little verbose, but nothing a good
>> editor or IDE (or anything better than gmail's web interface :-))
>> wouldn't make straightforward to manage.
> Could we use semicolons in the subscript to create a tuple? They could be
> used for packing or unpacking:
>     partner_id, product_id, ship_to, product_ids = values['partner_id';
> 'product_id'; 'ship_to'; 'product_ids']
>     my_dict['partner_id'; 'product_id'; 'ship_to'; 'product_ids'] =
> partner_id, product_id, ship_to, product_ids
> Or they would that be too easily confused with commas?

I'd imagine it would be confusing. And personally, I *still* find that
syntax less readable than the sequence of assignments.

Full disclosure - I've written that sort of sequence of assignments
quite a few times, and it's annoyed me every time I have. So I
sympathise with the desire for "something better". But now that we're
using real-world names, I'm finding that none of the proposed options
are actually qualifying as "better" - just "different"...


More information about the Python-ideas mailing list