Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101566
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!ecngs!testfeeder.ecngs.de!81.171.118.64.MISMATCH!peer04.fr7!news.highwinds-media.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:09:29 +0100 |
| Organization | None |
| Lines | 30 |
| Message-ID | <mailman.80.1452622185.13488.python-list@python.org> (permalink) |
| References | <f2711b57-7b11-4fd5-8bab-a3e8581177b5@googlegroups.com> <n73c6f$uec$1@ger.gmane.org> <CALwzid=wLxZF0Qd0ZOCQRxmhmx60XEGZjWTez+UzyLbR7_Arhg@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de G9j5zpKhpqvcPaiQgJC4sgFI0IgrenoqkhF/wcHOYP7Q== |
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.11; 'exception': 0.13; '2016': 0.16; 'called,': 0.16; 'fully,': 0.16; 'generator.': 0.16; 'propagated': 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; 'reedy': 0.16; 'url:whatsnew': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'am,': 0.23; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'coding': 0.27; 'values': 0.28; 'raise': 0.29; 'subject:/': 0.30; 'point': 0.33; 'url:python': 0.33; 'extract': 0.33; 'utility': 0.33; 'tue,': 0.34; 'except': 0.34; 'next': 0.35; 'desirable': 0.35; 'url:dev': 0.35; 'something': 0.35; 'should': 0.36; 'url:org': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; '12,': 0.37; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'url:3': 0.60; 'skip:n 10': 0.62; 'more': 0.63; '>>>>>': 0.66; 'subject:value': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8ad4.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 <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> |
| X-Received-Bytes | 3622 |
| X-Received-Body-CRC | 443918138 |
| Xref | csiph.com comp.lang.python:101566 |
Show key headers only | View raw
Ian Kelly wrote:
> On Tue, Jan 12, 2016 at 10:12 AM, Terry Reedy <tjreedy@udel.edu> wrote:
>> Using the values views at intended (as an iterable):
>>
>>>>> dv = d.values()
>>>>> next(iter(dv))
>> 1
>
> Good coding practice also dictates that whenever next is called, the
> potential StopIteration exception must be caught unless it is clearly
> intended to be propagated up to some generator.
Even then you should be prepared for
https://docs.python.org/dev/whatsnew/3.5.html#pep-479-change-stopiteration-handling-inside-generators
> So more fully, this
> should be something like:
>
> dv = iter(d.values())
> try:
> next(dv)
> except StopIteration:
> raise IndexError("d is empty")
>
> At which point it may be desirable to extract that into a utility
> function.
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