Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101553
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Emanuel Barry <vgr255@live.ca> |
| Newsgroups | comp.lang.python |
| Subject | RE: subscripting Python 3 dicts/getting the only value in a Python 3 dict |
| Date | Tue, 12 Jan 2016 12:00:06 -0500 |
| Lines | 20 |
| Message-ID | <mailman.70.1452618016.13488.python-list@python.org> (permalink) |
| References | <f2711b57-7b11-4fd5-8bab-a3e8581177b5@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de UKjgeRgP7tIwIQrTQzbeggbnN6q+bHbZMMBhaL5dz3Gw== |
| Return-Path | <vgr255@live.ca> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'preferably': 0.05; 'subject:getting': 0.07; 'item,': 0.09; 'python': 0.10; '>>>': 0.15; 'subject: \n ': 0.15; 'value.': 0.15; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:` 20': 0.18; '>': 0.18; '>>>': 0.20; 'all,': 0.20; 'to:name:python-list@python.org': 0.20; 'problem:': 0.22; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; 'equivalent': 0.27; 'dictionary': 0.29; 'seemingly': 0.29; 'subject:/': 0.30; 'code': 0.30; "i'd": 0.31; 'probably': 0.31; 'that,': 0.34; 'item': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'one,': 0.37; 'doing': 0.38; 'whatever': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'is.': 0.63; 'obvious': 0.76; 'it"': 0.84; 'subject:value': 0.84; 'write:': 0.91 |
| X-TMN | [BCQbA8PJOKW4wD9xX9AqqXRRDrLYJhej] |
| X-Originating-Email | [vgr255@live.ca] |
| Importance | Normal |
| In-Reply-To | <f2711b57-7b11-4fd5-8bab-a3e8581177b5@googlegroups.com> |
| X-OriginalArrivalTime | 12 Jan 2016 17:00:06.0874 (UTC) FILETIME=[B02F4BA0:01D14D5A] |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:101553 |
Show key headers only | View raw
> Hi all,
>
> Seemingly simple problem:
>
> There is a case in my code where I know a dictionary has only one item in it. I want to get the value of that item, whatever the key is.
>
> In Python2 I'd write:
>
> >>> d = {"Wilf's Cafe": 1}
> >>> d.values()[0]
> 1
The equivalent in Python 3 is `list(d.values())[0]`
> None of this feels like the "one, and preferably only one, obvious way to do it" we all strive for. Any other ideas?
If you feel like doing that, `for v in d.values(): pass` will set `v` to your value. But it's a bit cryptic, so you can probably resort to the list() alternative above :)
- Emanuel
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
subscripting Python 3 dicts/getting the only value in a Python 3 dict Nick Mellor <thebalancepro@gmail.com> - 2016-01-12 08:50 -0800
RE: subscripting Python 3 dicts/getting the only value in a Python 3 dict Emanuel Barry <vgr255@live.ca> - 2016-01-12 12:00 -0500
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Chris Angelico <rosuav@gmail.com> - 2016-01-13 04:06 +1100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Terry Reedy <tjreedy@udel.edu> - 2016-01-12 12:12 -0500
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-12 15:18 -0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Peter Otten <__peter__@web.de> - 2016-01-12 18:32 +0100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-12 10:39 -0700
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-12 19:47 +0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Marko Rauhamaa <marko@pacujo.net> - 2016-01-12 21:42 +0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-12 22:18 +0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Peter Otten <__peter__@web.de> - 2016-01-12 19:09 +0100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-12 16:48 -0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Peter Otten <__peter__@web.de> - 2016-01-12 19:59 +0100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-12 17:12 -0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Steven D'Aprano <steve@pearwood.info> - 2016-01-13 12:29 +1100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-13 13:53 -0200
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Steven D'Aprano <steve@pearwood.info> - 2016-01-13 12:23 +1100
Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict Grant Edwards <invalid@invalid.invalid> - 2016-01-13 15:58 +0000
csiph-web