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

2010-10-31 Thread cbr...@cbrownsystems.com
On Oct 31, 4:27 pm, Lawrence D'Oliveiro wrote: > In message > <687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>, > > cbr...@cbrownsystems.com wrote: > > I should note that efficiency is not an issue to me here; this is for > > when you have, say, a list user_options of at most aro

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

2010-10-31 Thread Lawrence D'Oliveiro
In message <687bcb76-0093-4d68-ba56-0390a3e1e...@30g2000yql.googlegroups.com>, cbr...@cbrownsystems.com wrote: > I should note that efficiency is not an issue to me here; this is for > when you have, say, a list user_options of at most around 15 options > or so, and you want to perform some actio

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

2010-10-31 Thread Lawrence D'Oliveiro
In message <4cca5aaf$0$1600$742ec...@news.sonic.net>, John Nagle wrote: > This is cheaper than intersection ... All together now: “PREMATURE OPTIMIZATION IS THE ROOT OF ALL EVIL!” -- http://mail.python.org/mailman/listinfo/python-list

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

2010-10-29 Thread cbr...@cbrownsystems.com
On Oct 29, 2:43 am, Steven D'Aprano wrote: > On Thu, 28 Oct 2010 09:16:42 -0700, cbr...@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

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

2010-10-29 Thread Adam Przybyla
cbr...@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

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

2010-10-29 Thread Steven D'Aprano
On Thu, 28 Oct 2010 09:16:42 -0700, cbr...@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

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

2010-10-29 Thread Xavier Ho
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" wrote: > On Oct 28, 6:16 pm, "cbr...@cbrownsystems.com" > wrote: >> It's clear but tedious to write: >> >> if 'monday" in days_off or "tu

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

2010-10-29 Thread HEK
On Oct 28, 6:16 pm, "cbr...@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 be

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

2010-10-29 Thread Carl Banks
On Oct 28, 10:50 pm, Paul Rubin wrote: > John Nagle writes: > >    d1 = set('monday','tuesday') > >    days_off = set('saturday','sunday') > >    if not d1.isdisjoint(days_off) :... > >    This is cheaper than intersection, since it doesn't have to > > allocate and construct a set. It just tests

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

2010-10-29 Thread cbr...@cbrownsystems.com
On Oct 28, 11:56 am, Arnaud Delobelle wrote: > "cbr...@cbrownsystems.com" writes: > > 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

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

2010-10-28 Thread Xavier Ho
On 29 October 2010 15:50, Paul Rubin wrote: > John Nagle writes: > >d1 = set('monday','tuesday') > >days_off = set('saturday','sunday') > >if not d1.isdisjoint(days_off) :... > >This is cheaper than intersection, since it doesn't have to > > allocate and construct a set. It just

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

2010-10-28 Thread Paul Rubin
John Nagle writes: >d1 = set('monday','tuesday') >days_off = set('saturday','sunday') >if not d1.isdisjoint(days_off) :... >This is cheaper than intersection, since it doesn't have to > allocate and construct a set. It just tests whether any element in the > smaller of the two sets

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

2010-10-28 Thread John Nagle
On 10/28/2010 9:23 AM, John Posner wrote: On 10/28/2010 12:16 PM, cbr...@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]): doSome

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

2010-10-28 Thread Arnaud Delobelle
"cbr...@cbrownsystems.com" writes: > 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 idio

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

2010-10-28 Thread cbr...@cbrownsystems.com
On Oct 28, 10:05 am, Chris Rebert wrote: > On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com > > > > wrote: > > On Oct 28, 9:23 am, John Posner wrote: > >> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: > > >> > It's clear but tedious to write: > > >> > if 'monday" in days_off o

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

2010-10-28 Thread nn
On Oct 28, 12:33 pm, "cbr...@cbrownsystems.com" wrote: > On Oct 28, 9:23 am, John Posner wrote: > > > > > On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: > > > > It's clear but tedious to write: > > > > if 'monday" in days_off or "tuesday" in days_off: > > >      doSomething > > > > I cur

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

2010-10-28 Thread Chris Rebert
On Thu, Oct 28, 2010 at 9:33 AM, cbr...@cbrownsystems.com wrote: > On Oct 28, 9:23 am, John Posner wrote: >> On 10/28/2010 12:16 PM, cbr...@cbrownsystems.com wrote: >> >> > It's clear but tedious to write: >> >> > if 'monday" in days_off or "tuesday" in days_off: >> >      doSomething >> >> > I c

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

2010-10-28 Thread Chris Kaynor
On Thu, Oct 28, 2010 at 9:16 AM, cbr...@cbrownsystems.com < cbr...@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]

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

2010-10-28 Thread cbr...@cbrownsystems.com
On Oct 28, 9:23 am, John Posner wrote: > On 10/28/2010 12:16 PM, cbr...@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']

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

2010-10-28 Thread John Posner
On 10/28/2010 12:16 PM, cbr...@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

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

2010-10-28 Thread cbr...@cbrownsystems.com
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? Cheers - Chas -- http://mail.p