which one is more efficient
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Feb 11 07:18:39 EST 2008
Paul Rubin a écrit :
>> ki lo wrote:
>>> I have type variable which may have been set to 'D' or 'E'
>>>
>>> Now, which one of following statements are more efficient
>>>
>>> if type =='D' or type == 'E':
>>>
>>> or
>>>
>>> if re.search("D|E", type):
>>>
>>> Please let me know because the function is going to called 10s of millions
>>> of times.
>> For maximum efficiency you have to use a set.
>
> if type in 'DE': ...
>
> might be faster.
It might also be wrong if there's a possibility that type=='DE' :
>>> "DE" in "DE"
True
More information about the Python-list
mailing list