Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Date: Tue, 12 Jan 2016 19:59:14 +0100 Organization: None Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de RITjILlqTmUZYHkE6j0fQw2rUvz9lS7n9850WW4um92w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'subject:getting': 0.07; 'trailing': 0.07; 'brackets': 0.09; 'foo,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'jan': 0.11; '2016': 0.16; 'comma,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'consistent': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'looks': 0.29; 'there.': 0.30; 'subject:/': 0.30; 'tue,': 0.34; 'item': 0.35; 'but': 0.36; 'there': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; '12,': 0.37; 'wrong': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'personally': 0.61; '>>>>>': 0.66; 'here': 0.66; 'bernardo': 0.84; 'otten': 0.84; 'subject:value': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8788.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101569 Bernardo Sulzbach wrote: > On Tue, Jan 12, 2016 at 3:32 PM, Peter Otten <__peter__@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. > [k] = d.values() works the same. I used the tuple here to keep it consistent with all other cases where the brackets are superfluous, like [foo, *bar] = ... foo, *bar = ... etc.