question about True values

Antoon Pardon apardon at forel.vub.ac.be
Sat Oct 28 15:40:50 CEST 2006


On 2006-10-28, Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> wrote:
> On Fri, 27 Oct 2006 18:22:28 +0000, Antoon Pardon wrote:
>
>>>> And how do I express that a number has to be greater than
>>>> 100 into a Nothing vs Something dichotomy? Declare all
>>>> greater numbers as Something and the rest as Nothing?
>>>
>>> Well, would you declare numbers less than 100 False?
>> 
>> No but the condition: x > 100, will map all numbers to
>> either True or False. Can you provide a condition that will
>> provide a mapping to Nothing and Something? Without
>> artificially mapping False to Nothing and True to Something?
>
> A > B maps to max(0, A-B)
>
> or more verbosely, "Remove B items from A items, stopping when there are
> no more items to remove. What is left over? Something or Nothing?"

This mapping no longer works if you are not working with numbers.

>>> A = [1,2]     
>>> B = [3]
>>> A > B
False
>>> max(0, A - B)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'list' and 'list'

-- 
Antoon Pardon



More information about the Python-list mailing list