merits of Lisp vs Python
Christophe Cavalaria
chris.cavalaria at free.fr
Fri Dec 15 09:50:04 EST 2006
Paul Rubin wrote:
> André Thieme <address.good.until.2006.dec.22 at justmail.de> writes:
>> def nif(num, pos, zero, neg):
>> if num > 0:
>> return pos
>> else:
>> if num == 0:
>> return zero
>> else:
>> return neg
>
> def nif(num, pos, zero, neg):
> return (neg, zero, pos)[cmp(num, 0)+1]
Since we are in one liners, let's be even smarter and do it like that :
def nif(num, pos, zero, neg):
return (zero, pos, neg)[cmp(num, 0)]
;)
More information about the Python-list
mailing list