Pythonic way of saying 'at least one of a, b, or c is in some_list'

Adam Przybyla adam at rybnik.pl
Fri Oct 29 05:47:04 EDT 2010


cbrown at cbrownsystems.com <cbrown at cbrownsystems.com> wrote:
> It's clear but tedious to write:
> 
> if 'monday" in days_off or "tuesday" in days_off:
>    doSomething
> 
> I currently am tending to write:
> 
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
>    doSomething
> 
> Is there a better pythonic idiom for this situation?
	... hmmm, try this:
if set(['monday', 'tuesday'])&set(days_off):
	dosomething
Regards
								Adam Przybyla



More information about the Python-list mailing list