[Python-ideas] Fwd: quantifications, and tuple patterns
p.f.moore at gmail.com
Sun Jan 15 09:59:43 CET 2012
On 15 January 2012 02:27, Nick Coghlan <ncoghlan at gmail.com> wrote:
> That means, the example can already be written as:
> for p1 in (p for slot, p in decisions if slot == slot_num):
> if any(True for slot, p2 in proposals if slot == slot_num and p2 != p1):
> # Do something!
Actually, that may not work - the original requirement was to scan
decisions on each iterations, and pick one item that satisfied the
condition each time. If decisions is changing each iteration, you need
to rescan each time, which your for loop doesn't do.
I think that's why the (otherwise odd) "while there are any, pick one"
construct is used. Of course, for an algorithm like that, I'd probably
tend to choose a different data structure, maybe something like a work
More information about the Python-ideas