Pythonic way of saying 'at least one of a, b, or c is in some_list'
arnodel at gmail.com
Thu Oct 28 20:56:48 CEST 2010
"cbrown at cbrownsystems.com" <cbrown at cbrownsystems.com> writes:
> 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?
The latter can be written more concisely:
if any(d in days_off for d in ['monday', 'tuesday']):
# do something
More information about the Python-list