[Python-ideas] Unpacking a dict

Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 26 18:20:44 EDT 2016


Steven D'Aprano wrote:
> I believe that, by far the majority of the time, you will be repeating the
> same names twice, and likely exceeding most reasonable line lengths:
> 
> 'referer': referer, 'useragent': useragent, 'use_proxy': use_proxy,
>   'follow_links': follow_links, 'clobber': clobber, 'timeout': timeout =
>   mapping

I think a more realistic usage would be to give short local
names to something having long keys.

    ('referer': ref, 'useragent': ua, 'use_proxy': prox,
       'follow_links': fl, 'clobber': clob, 'timeout': to) = mapping

So tying the keys to the names of the target variables
might be too restrictive.

-- 
Greg


More information about the Python-ideas mailing list