Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20504

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

References <jhhfc6$go$1@news.albasani.net> <mailman.5868.1329350900.27778.python-list@python.org> <jhhl4o$2ar$1@news.albasani.net> <CALwzidmVESk0cqYfk7+tyXaumKoN3DShfPAwBh4O1t=JHZZyZw@mail.gmail.com>
Date 2012-02-16 07:59 +0000
Subject Re: Wanted: Criticism of code for a Python module, plus a Mac tester
From Arnaud Delobelle <arnodel@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5877.1329379194.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 16 February 2012 05:03, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster <someone@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Wanted: Criticism of code for a Python module, plus a Mac tester HoneyMonster <someone@someplace.invalid> - 2012-02-15 23:33 +0000
  Re: Wanted: Criticism of code for a Python module, plus a Mac tester Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-15 17:07 -0700
    Re: Wanted: Criticism of code for a Python module, plus a Mac tester HoneyMonster <someone@someplace.invalid> - 2012-02-16 01:11 +0000
      Re: Wanted: Criticism of code for a Python module, plus a Mac tester Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-15 22:03 -0700
      Re: Wanted: Criticism of code for a Python module, plus a Mac tester Arnaud Delobelle <arnodel@gmail.com> - 2012-02-16 07:59 +0000
  Re: Wanted: Criticism of code for a Python module, plus a Mac tester Tim Chase <python.list@tim.thechases.com> - 2012-02-15 18:43 -0600

csiph-web