Re: A and B but not C in list

2011-01-28 Thread CM
Thanks, everyone, for your suggestions. -Che -- http://mail.python.org/mailman/listinfo/python-list

Re: A and B but not C in list

2011-01-26 Thread Arnaud Delobelle
Terry Reedy writes: > On 1/23/2011 4:05 PM, CM wrote: >> In Python, is there a recommended way to write conditionals of the >> form: >> >> "if A and B but not C or D in my list, do something." ? >> >> I may also have variations on this, like "if A but not B, C, or D". >> >> Do I have to just wri

Re: A and B but not C in list

2011-01-24 Thread Boris Borcic
Terry Reedy wrote: The straightforward code if a in L and b in L and c not in L and d not in L scans the list 4 times. of course for a single scan one can setify the list and write S=set(L) if a in S and b in S and c not in S and d not in S or even, I guess, something like {a,b} <= S and

Re: A and B but not C in list

2011-01-24 Thread Christian Heimes
Am 24.01.2011 04:05, schrieb Ian Kelly: > On Sun, Jan 23, 2011 at 2:34 PM, Christian Heimes wrote: >> your_set = set(your_list) >> >> if your_set.issuperset(set([A, B])) and your_set.isdisjoint(set([C, D])): > > if your_set.intersection([A, B, C, D]) == set([A, B]): > ... Ingenious but trick

Re: A and B but not C in list

2011-01-24 Thread Peter Otten
Ian Kelly wrote: > On Sun, Jan 23, 2011 at 2:34 PM, Christian Heimes > wrote: >> your_set = set(your_list) >> >> if your_set.issuperset(set([A, B])) and your_set.isdisjoint(set([C, D])): > > if your_set.intersection([A, B, C, D]) == set([A, B]): > ... You can avoid converting your_list to a

Re: A and B but not C in list

2011-01-23 Thread Ian Kelly
On Sun, Jan 23, 2011 at 2:34 PM, Christian Heimes wrote: > your_set = set(your_list) > > if your_set.issuperset(set([A, B])) and your_set.isdisjoint(set([C, D])): if your_set.intersection([A, B, C, D]) == set([A, B]): ... Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: A and B but not C in list

2011-01-23 Thread Terry Reedy
On 1/23/2011 4:05 PM, CM wrote: In Python, is there a recommended way to write conditionals of the form: "if A and B but not C or D in my list, do something." ? I may also have variations on this, like "if A but not B, C, or D". Do I have to just write out all the if and elifs with all possib

Re: A and B but not C in list

2011-01-23 Thread Steven D'Aprano
On Sun, 23 Jan 2011 22:34:33 +0100, Christian Heimes wrote: > It's easier and faster if you convert the lists to sets first: > > your_set = set(your_list) > > if your_set.issuperset(set([A, B])) and your_set.isdisjoint(set([C, > D])): > ... "Easier" is a close thing. I find this easier to r

Re: A and B but not C in list

2011-01-23 Thread Christian Heimes
Am 23.01.2011 22:05, schrieb CM: > In Python, is there a recommended way to write conditionals of the > form: > > "if A and B but not C or D in my list, do something." ? > > I may also have variations on this, like "if A but not B, C, or D". > > Do I have to just write out all the if and elifs

Re: A and B but not C in list

2011-01-23 Thread Chris Rebert
On Sun, Jan 23, 2011 at 1:05 PM, CM wrote: > In Python, is there a recommended way to write conditionals of the > form: > > "if A and B but not C or D in my list, do something."  ? > > I may also have variations on this, like "if A but not B, C, or D". > > Do I have to just write out all the if an

Re: A and B but not C in list

2011-01-23 Thread Corey Richardson
On 01/23/2011 04:05 PM, CM wrote: In Python, is there a recommended way to write conditionals of the form: "if A and B but not C or D in my list, do something." ? I may also have variations on this, like "if A but not B, C, or D". Do I have to just write out all the if and elifs with all poss

A and B but not C in list

2011-01-23 Thread CM
In Python, is there a recommended way to write conditionals of the form: "if A and B but not C or D in my list, do something." ? I may also have variations on this, like "if A but not B, C, or D". Do I have to just write out all the if and elifs with all possible conditions, or is there a handi