Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #4329
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Mike Müller <mmueller@python-academy.de> |
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] Schleifen die ohne Durchlaufen des Schleifenkörpers beendet wurden |
| Date | Fri, 25 Mar 2016 12:49:00 +0100 |
| Organization | Python Academy GmbH & Co. KG |
| Lines | 96 |
| Message-ID | <mailman.1.1458907747.28225.python-de@python.org> (permalink) |
| References | <56F445C9.3000200@mail.de> <CAMSP2L7OBP5h4yjrRrx4XuvwE3UMTg=grZqPzJ7B9ZEyYYXD5A@mail.gmail.com> <E7199327-B882-4691-A703-351C20DFE173@web.de> <A201B172-63F7-484B-80FB-EB92999275A7@darwin.in-berlin.de> <533CBF60-D919-4211-8155-ACC90B848839@web.de> <56F47AD1.5040008@chrisarndt.de> |
| Reply-To | mmueller@python-academy.de |
| Mime-Version | 1.0 |
| Content-Type | multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XMKHeorkVfRGc20enCOc1Eqcw7eiDtvip" |
| X-Trace | news.uni-berlin.de RnBsOdnahsFpNUJuOYbwiAJDqjfxo3MHK6VBomFI044w== |
| Return-Path | <mmueller@python-academy.de> |
| X-Original-To | python-de@python.org |
| Delivered-To | python-de@mail.python.org |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <56F47AD1.5040008@chrisarndt.de> |
| X-Authenticated-Sender | mmueller@python-academy.de |
| X-Virus-Scanned | Clear (ClamAV 0.99/21473/Thu Mar 24 21:25:24 2016) |
| X-BeenThere | python-de@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | Die Deutsche Python Mailingliste <python-de.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-de/> |
| List-Post | <mailto:python-de@python.org> |
| List-Help | <mailto:python-de-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe> |
| Xref | csiph.com de.comp.lang.python:4329 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Am 25.03.16 um 00:40 schrieb Christopher Arndt:
> Am 24.03.2016 um 23:46 schrieb Diez B. Roggisch:
>> Huh, im Zeitalter von ternary if’s noch den OR-Trick ;)
>
> Der "OR-Trick" ist auch in Zeiten von "expr if expr else expr" noch des
> öfteren hilfreich weil oft kürzer. Er ist ja eigentlich nur eine andere
> Form von "expr1 if expr1 else expr2" (wobei expr1 nur einmal evaluiert
> wird).
>
> Was man nicht mehr verwenden sollte, ist "expr and non-false-expr or expr".
>
>> Ich denke wenn wuerde ich das eher kapseln in ein
>>
>> def loop_or_else(iterable, sideeffect):
>> looped = False
>> for item in iterable:
>> looped = True
>> yield item
>> if not looped:
>> sideeffect()
>
> Wenn man weiß, dass ein bestimmter Wert niemals ein Element des
> Iterables sein wird, kann man das auch so verkürzen:
>
> i = SENTINEL
> for i in collection:
> do_item(i)
> if i == SENTINEL:
> and_now_for_something_completely_different()
>
> Ist immerhin nur eine Zeile mehr als die usprl. geforderte Lösung.
Ich würde das so machen:
senti = senti_start = object()
for i in collection:
senti = do_item()
if senti is senti_start:
empty()
object() ist der Sentinel schlechthin.
Alle Funktionen haben immer einen Rückgabewert. Damit muss ich `i`
nicht zwingend als Argument mitgeben.
Viele Grüße
Mike
Back to de.comp.lang.python | Previous | Next | Find similar
Re: [Python-de] Schleifen die ohne Durchlaufen des Schleifenkörpers beendet wurden Mike Müller <mmueller@python-academy.de> - 2016-03-25 12:49 +0100
csiph-web