Pythonic way of saying 'at least one of a, b, or c is in some_list'
contact at xavierho.com
Fri Oct 29 10:31:08 CEST 2010
Not sure why you use the for-else syntax without a break or continue. And
I'm also not sure on the readability.
-Xav on his Froyo
On 29/10/2010 6:21 PM, "HEK" <elkarouh at gmail.com> wrote:
> On Oct 28, 6:16 pm, "cbr... at cbrownsystems.com"
> <cbr... at cbrownsystems.com> wrote:
>> It's clear but tedious to write:
>> if 'monday" in days_off or "tuesday" in days_off:
>> I currently am tending to write:
>> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
>> Is there a better pythonic idiom for this situation?
>> Cheers - Chas
> The most pythonic way is the following:
> class anyof(set):
> def __contains__(self,item):
> if isinstance(item,anyof):
> for it in item:
> if self.__contains__(it):
> return True
> return False
> return super(anyof,self).__contains__(item)
> assert anyof(['monday','tuesday']) in daysoff
> best regards
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list