Searching for most pythonic/least stupid way to do something simple

david jensen dmj.ccc at gmail.com
Tue Mar 16 17:31:36 CET 2010


Thanks Paul, but i don't immediately see how that helps (maybe I'm
just being dense)... nn's solution, though i initially thought it
worked, actually has a similar problem:

intended:
>>> print getOutcomes([3,4,5,5])
[[6, 1, 5, 5], [4.5, 2.5, 5, 5], [3, 4, 5, 5], [1.5, 5.5, 5, 5], [0,
7, 5, 5]]
>>> print getOutcomes([4,3,5,5])
[[7, 0, 5, 5], [5.5, 1.5, 5, 5], [4, 3, 5, 5], [2.5, 4.5, 5, 5], [1,
6, 5, 5]]

nn's solution:
>>> print getOutcomesNN([4,3,5,5])
[[6.0, 1.0, 5, 5], [4.5, 2.5, 5, 5], [3.0, 4.0, 5, 5], [1.5, 5.5, 5,
5], [0.0, 7.0, 5, 5]]


it's obvious why this is happening (the list comprehension assumes
that index 0 is, after all, index 0), but not immediately obvious how
to fix it, except by going with gerard's solution or doing what i did
in the beginning: flip them if they're in the wrong order, remember,
and flip them again at the end.

dmj



More information about the Python-list mailing list