On 2016-01-13, Steven D'Aprano <st...@pearwood.info> wrote:
> Probably the best solution, because it will conveniently raise an exception
> if your assumption that the dict has exactly one item is wrong:
>
> item, = d.values()  # Note the comma after "item".

[...]

> but you can unpack a sequence of one item too. If you really want to make it
> obvious that the comma isn't a typo:
>
> (item,) = d.values()

If it were I, I'd definitely do the later.  I used to do it the first
way, but I often times would not notice the comma later when
maintaining the code and end up wasting an embarassing amount of time
when what should have been an easy, trivial change broke.

-- 
Grant Edwards               grant.b.edwards        Yow! It was a JOKE!!
                                  at               Get it??  I was receiving
                              gmail.com            messages from DAVID
                                                   LETTERMAN!!  !
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to