Pythonic way of saying 'at least one of a, b, or c is in some_list'
ckaynor at zindagigames.com
Thu Oct 28 18:38:32 CEST 2010
On Thu, Oct 28, 2010 at 9:16 AM, 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:
> I currently am tending to write:
> if any([d for d in ['monday', 'tuesday'] if d in days_off]):
A slightly cleaner form would be:
if any(day in days_off for day in ['Monday', 'Tuesday']):
To make that a bit easier to read:
if any((day in days_off) for day in ['Monday', 'Tuesday']):
> Is there a better pythonic idiom for this situation?
> Cheers - Chas
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list