returning True, False or None
Steven Bethard
steven.bethard at gmail.com
Fri Feb 4 13:14:23 EST 2005
Raymond Hettinger wrote:
> "Steven Bethard"
>
>>For a given list:
>>* If all values are None, the function should return None.
>>* If at least one value is True, the function should return True.
>>* Otherwise, the function should return False.
>
> . . .
>
>>Right now, my code looks like:
>>
>> if True in lst:
>> return True
>> elif False in lst:
>> return False
>> else:
>> return None
>>
>>This has a light code smell for me though -- can anyone see a simpler
>>way of writing this?
>
>
> return max(lst)
Very clever! Thanks!
Steve
More information about the Python-list
mailing list