subscripting Python 3 dicts/getting the only value in a Python 3 dict

Bernardo Sulzbach mafagafogigante at gmail.com
Tue Jan 12 13:48:17 EST 2016


On Tue, Jan 12, 2016 at 3:32 PM, Peter Otten <__peter__ at web.de> wrote:
>
> If there is exactly one item you can unpack:
>
>>>> d = {"Wilf's Cafe": 1}
>>>> k, = d.values()
>>>> k
> 1
>

I personally don't like that trailing comma, it just looks wrong
there. But this is very neat.

-- 
Bernardo Sulzbach



More information about the Python-list mailing list