Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repetition,': 0.16; 'true:': 0.16; 'zero,': 0.16; 'bit': 0.19; 'thoughts': 0.19; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'header:X-Complaints-To:1': 0.27; 'generally': 0.29; 'url:wiki': 0.31; 'writes:': 0.31; 'url:python': 0.33; 'common': 0.35; 'skip:s 30': 0.35; 'there': 0.35; 'url:org': 0.36; 'ben': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'use.': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'break': 0.61; 'url:3': 0.61; 'more': 0.64; 'empire': 0.84; 'received:125': 0.84; 'subject:Extension': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Extension of while syntax Date: Fri, 12 Dec 2014 13:37:33 +1100 References: <14d2b880-3837-4267-a769-33ae7393f78b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:lkg2cm9CG2lVNZOQ/06CxYInXHA= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418351865 news.xs4all.nl 2877 [2001:888:2000:d::a6]:57966 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82405 Nelson Crosby writes: > I was thinking a bit about the following pattern: > > value = get_some_value() > while value in undesired_values: > value = get_some_value() I think that's an anti-pattern (because of the repetition, as you say). An improvement:: value = some_default_value_such_as_None while value in undesired_values: value = get_some_value() More common and generally useful:: while True: value = get_some_value() if value not in undesired_values: break > What are other's thoughts on this? I think there are already clean ways to deal with this in common use. -- \ “… one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.” —Robert Firth | Ben Finney