Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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: UNSURE 0.217 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.65; '*S*': 0.08; 'received:134': 0.05; 'familiarity': 0.07; 'toggle': 0.09; 'itertools': 0.16; 'loops': 0.16; 'library': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'writes:': 0.31; 'url:python': 0.33; 'url:org': 0.36; 'turn': 0.37; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'url:3': 0.61; 'skip:n 10': 0.64; 'become': 0.64; 'between': 0.67; '03:42': 0.84; 'colour': 0.84; 'fast,': 0.84; 'indefinitely': 0.84; 'pardon': 0.84; '\xe2\x80\xa6': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqcEABbGN1SGuA9G/2dsb2JhbABgg2FYgwbIS4dNAoEeAYR/AQEEIw8BRRELGgIFFgsCAgkDAgECAUUTCAIXiA8DEQ2tZI57hgwBAQgBAQEBGgSBLI8fFoJhgVQBBJMAgzuHEIdOjkODeWoBAYJIAQEB Date: Fri, 10 Oct 2014 13:44:08 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Toggle References: <857g0at3wp.fsf@benfinney.id.au> In-Reply-To: <857g0at3wp.fsf@benfinney.id.au> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 10 Oct 2014 13:57:19 +0200 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412942241 news.xs4all.nl 2965 [2001:888:2000:d::a6]:58593 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3475 X-Received-Body-CRC: 4244816300 Xref: csiph.com comp.lang.python:78946 Op 09-10-14 om 03:42 schreef Ben Finney: > Seymore4Head writes: > >> I want to toggle between color="Red" and color="Blue" > It's good to cultivate ongoing familiarity with the standard library > > so that you can make use of wheels already invented and maintained:: > > import itertools > > colours = ["Red", "Blue"] > colour_cycle = itertools.cycle(colours) > > next(colour_cycle) # → "Red" > next(colour_cycle) # → "Blue" > next(colour_cycle) # → "Red" > next(colour_cycle) # → "Blue" > next(colour_cycle) # → "Red" > > for colour in colour_cycle: > # … loops indefinitely > # with ‘colour’ bound to each value in turn … I think this solution will become rather involved fast, when you have multiple toggles. -- Antoon Pardon