Wanted: Criticism of code for a Python module, plus a Mac tester
Arnaud Delobelle
arnodel at gmail.com
Thu Feb 16 02:59:50 EST 2012
More information about the Python-list mailing list
Thu Feb 16 02:59:50 EST 2012
- Previous message (by thread): Wanted: Criticism of code for a Python module, plus a Mac tester
- Next message (by thread): format a measurement result and its error in "scientific" way
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 16 February 2012 05:03, Ian Kelly <ian.g.kelly at gmail.com> wrote: > On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster <someone at someplace.invalid> 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. I believe this generates > the correct result, although adding None to the dealers list is > somewhat unsatisfactory: > > DEALERS = ["Dealer North", "Dealer East", "Dealer South", "Dealer West", None] > VULNERABILITIES = [ > "Neither vulnerable", "North-South vulnerable", > "East-West vulnerable", "Both vulnerable", > ] > CONDITIONS = [(d, v) for (d, v) in zip(DEALERS * 4, VULNERABILITIES * 5) if d] You could also do: DEALERS = ["Dealer North", "Dealer East", "Dealer South", "Dealer West"] VULNERABILITIES = [ "Neither vulnerable", "North-South vulnerable", "East-West vulnerable", "Both vulnerable", ] CONDITIONS = [ (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 = itertools.product(DEALERS, VULNERABILITIES) (But maybe you do, I haven't looked at the code) -- Arnaud
- Previous message (by thread): Wanted: Criticism of code for a Python module, plus a Mac tester
- Next message (by thread): format a measurement result and its error in "scientific" way
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list