Searching for most pythonic/least stupid way to do something simple
Paul Rubin
no.email at nospam.invalid
Tue Mar 16 11:09:37 EDT 2010
david jensen <dmj.ccc at gmail.com> writes:
> Obviously, i can just write the code again, in an else, switching
> indices 0 and 1. Or, I could just have a test at the beginning, switch
> them if they are in the order "big, small", and then switch them again
> at the end in a list comprehension. Both ideas seem terribly silly,
> and there must be an obvious way to do it that I'm not seeing.
Generally when faced with this kind of question, see if you can
use the built-in min and max functions:
def getOutcomes():
outcomes=[]
smaller = min(myList[0], myList[1])
bigger = max(myList[0], myList[1])
amountToShare=2*smaller
remainder = bigger - smaller
...
More information about the Python-list
mailing list