Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Date: Wed, 13 Jan 2016 15:58:23 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 23 Message-ID: References: <5695a72a$0$1583$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1452700703 23598 67.130.15.94 (13 Jan 2016 15:58:23 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 13 Jan 2016 15:58:23 +0000 (UTC) User-Agent: slrn/1.0.2 (Linux) Xref: csiph.com comp.lang.python:101627 On 2016-01-13, Steven D'Aprano 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!! !