[Python-ideas] Unpacking a dict

MRAB python at mrabarnett.plus.com
Thu May 26 15:48:36 EDT 2016


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?



More information about the Python-ideas mailing list