if statement multiple or

Tim Golden mail at timgolden.me.uk
Fri May 6 09:31:41 EDT 2011


On 06/05/2011 14:17, scattered wrote:
> On May 6, 8:25 am, Christian Heimes<li... at cheimes.de>  wrote:
>> Am 06.05.2011 14:09, schrieb scattered:
>>
>>> sets could also work
>>
>>> if set('abc')&  set(line) == set():
>>>       print line
>>
>> Right!
>> Sets work in this special case, because the OP just wants to search for
>> a single char. It won't work for longer strings, though.
>>
>> Also I would write the test as:
>>
>> if set(line).isdisjoint("abc"):
>>      print line
>>
>> Christian
>
> Thanks for the tip - I'm still learning Python and was unaware of the
> isdisjoint method.

If it's any consolation, I've been using Python for 10 years and
I was unaware of the isdisjoint method. :)

TJG



More information about the Python-list mailing list