Thanks, everyone, for your suggestions.
-Che
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
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
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
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
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
12 matches
Mail list logo