Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-2.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed5.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: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:module': 0.04; 'subject:Python': 0.05; 'subject:code': 0.07; 'ah,': 0.09; 'received:209.85.214.174': 0.13; 'result,': 0.15; 'listed,': 0.16; 'subject:Mac': 0.16; '\xc2\xa0i': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'wed,': 0.17; 'wrote:': 0.18; "haven't": 0.20; '(but': 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'do,': 0.25; 'suggestion': 0.26; 'cc:2**0': 0.26; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'correct': 0.29; 'pm,': 0.29; 'kelly': 0.30; 'list': 0.32; 'there': 0.33; 'none': 0.35; 'received:209.85.214': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.38; 'somewhat': 0.38; 'could': 0.38; 'some': 0.38; 'doing': 0.38; 'i.e.': 0.39; 'received:209': 0.39; 'more': 0.61; 'simple': 0.61; 'your': 0.61; 'believe': 0.65; 'care': 0.71; 'dealers': 0.84; 'subject:plus': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=gs2pKBAulbauI8cSRXWZ1iF2FKxNVWZiLpi1bhOFc24=; b=uEXzZWRv5jhYQp9jfLrbxz9x271AGPYs5JrJFoVOddRxhDMZAyTGE0bFmhDDgMVa0G X37UoAQbNv0Mez56eATNrW79A4/lXdVqpqaluT4KSEazOc8+huYNAxCQshV92ijMmPus 2PVvR5Gp9Ckpa1771mkgUou67Q88vkdW91Spc= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 16 Feb 2012 07:59:50 +0000 Subject: Re: Wanted: Criticism of code for a Python module, plus a Mac tester From: Arnaud Delobelle To: Ian Kelly Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1329379194 news.xs4all.nl 6923 [2001:888:2000:d::a6]:57040 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20504 On 16 February 2012 05:03, Ian Kelly wrote: > On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster = wrote: >> As to your first suggestion though, I am having some difficulty. Note >> that the vulnerability rotates; i.e. CONDITIONS[4] is not the same as >> CONDITIONS[0]. >> Is there a better way of doing it than a simple list.append()? > > Ah, it's more complicated than I realized. =C2=A0I believe this generates > the correct result, although adding None to the dealers list is > somewhat unsatisfactory: > > DEALERS =3D ["Dealer North", "Dealer East", "Dealer South", "Dealer West"= , None] > VULNERABILITIES =3D [ > =C2=A0 "Neither vulnerable", "North-South vulnerable", > =C2=A0 "East-West vulnerable", "Both vulnerable", > ] > CONDITIONS =3D [(d, v) for (d, v) in zip(DEALERS * 4, VULNERABILITIES * 5= ) if d] You could also do: DEALERS =3D ["Dealer North", "Dealer East", "Dealer South", "Dealer West"] VULNERABILITIES =3D [ =C2=A0 "Neither vulnerable", "North-South vulnerable", =C2=A0 "East-West vulnerable", "Both vulnerable", ] CONDITIONS =3D [ (DEALERS[j], VULNERABILITIES[(i + j)%4]) for i in range(4) for j in range(4) ] If you don't care about the order in which the conditions are listed, you could use CONDITIONS =3D itertools.product(DEALERS, VULNERABILITIES) (But maybe you do, I haven't looked at the code) --=20 Arnaud