Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20502
| References | <jhhfc6$go$1@news.albasani.net> <mailman.5868.1329350900.27778.python-list@python.org> <jhhl4o$2ar$1@news.albasani.net> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2012-02-15 22:03 -0700 |
| Subject | Re: Wanted: Criticism of code for a Python module, plus a Mac tester |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5876.1329368656.27778.python-list@python.org> (permalink) |
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]
I might be tempted to write a custom iterator for it, something like this:
def rotating(iterable):
cache = collections.deque()
for value in iterable:
yield value
cache.append(value)
while True:
cache.rotate(-1)
for value in cache:
yield value
# Using the original 4-length DEALERS list
CONDITIONS = list(itertools.islice(itertools.izip(itertools.cycle(DEALERS),
rotating(VULNERABILITIES)), 16))
But I don't know that it's really worth the added complexity.
Cheers,
Ian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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