PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

Ethan Furman ethan at stoneleaf.us
Thu Mar 19 11:42:48 EDT 2020


On 03/19/2020 02:09 AM, Terry Reedy wrote:
> On 3/18/2020 10:28 PM, Santiago Basulto wrote:
> 
>> For dictionaries it'd even be more useful:
>>      d = {
>>          'first_name': 'Frances',
>>          'last_name': 'Allen',
>>          'email': 'fallen at ibm.com'
>>      }
>>      fname, lname = d[['first_name', 'last_name']]
> 
> Insert ordered dicts make this sort of thing less useful.
> 
>  >>> d = {
>          'first_name': 'Frances',
>          'last_name': 'Allen',
>          'email': 'fallen at ibm.com'
> }
>  >>> fname, lname, _ = d
>  >>> fname, lname
> ('first_name', 'last_name')

I disagree -- the ordered dict would have to be small (maybe five entries) and one would have to know the insertion order.

--
~Ethan~


More information about the Python-list mailing list