[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Better way to negate a boolean list?

David Tremouilles

2/10/2008 5:52:00 PM

Thanks to all of you for the prompt answer to my question.

Just a short feedback:
>>> map(not_, boolean_list)
looks more readable to me
but:
>>> [not elem for elem in boolean_list]
seems to be slightly faster (ipython timeit results)
(python 2.5.1 MacOS X)

Not a big deal anyway!
Most important for me was to understand the strange "not" behavior.

Thanks again,

David


Gary Herron a écrit :
> David Trémouilles wrote:
>> Hi,
>>
>> Is there any better (shorter) way to negate a boolean list than:
>> >>> negated_boolean_list = [not elem for elem in boolean_list]
>> ?
>>
>> I tried:
>> >>> map(not, boolean_list)
>> but it seems that "not" is not a function.
>>
>> Thanks in advance,
>>
>> David
>>
> But import module operator, and find operator.not_ which is a function
> and does what you want.
>
> Gary Herron
>