On 01/05/2013 04:55 PM, Terry Reedy wrote:
> On 1/5/2013 1:58 PM, Dave Angel wrote:
>
>> If you're trying to make a faster loop, then I suggest you look into set
>> differences. Turn both lists into sets, and subtract them. Something
>> like (untested):
>>
>> result = not bool( set(lst1) -
On 1/5/2013 1:25 PM, Asim wrote:
Hi All
The following reduce expression checks if every element of list lst1
is present in list lst2. It works as expected for integer lists but
for lists of strings, it always returns False.
reduce( lambda x,y: (x in lst2) and (y in lst2), lst1)
reduce(lambda
On 1/5/2013 1:58 PM, Dave Angel wrote:
If you're trying to make a faster loop, then I suggest you look into set
differences. Turn both lists into sets, and subtract them. Something
like (untested):
result = not bool( set(lst1) - set(lst2) )
This does not return False as soon as an ite
Asim writes:
> Hi All
>
> The following reduce expression checks if every element of list lst1
> is present in list lst2. It works as expected for integer lists but
> for lists of strings, it always returns False.
>
>reduce( lambda x,y: (x in lst2) and (y in lst2), lst1)
Possibly this:
Because reduce doesn't do what you want. You'd want "all".
L1 = [1,2,3]
L2 = ["A1","B2","C3",1,2,3]
print all((x in L2 for x in L1)) # prints True
L3 = ["A1","B2","C3"]
print all((x in L2 for x in L3)) # prints True
- Original Message -
From: Asim
To: python-list@python.org
Cc:
Sent:
On 01/05/2013 01:25 PM, Asim wrote:
> Hi All
>
> The following reduce expression checks if every element of list lst1 is
> present in list lst2. It works as expected for integer lists but for lists
> of strings, it always returns False.
>
>reduce( lambda x,y: (x in lst2) and (y in lst2), lst