reduce expression to test sublist

Terry Reedy tjreedy at udel.edu
Sat Jan 5 22:55:50 CET 2013


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 item in set1 is found that is 
not in set2.

set(lst1) < set(lst2)

will, and directly return False/True. The OP is trying to compute the 
lst1 < lst2, where lst1 and lst2 are interpreted as sets, rather than as 
sequences with the lexicographic ordering default.

-- 
Terry Jan Reedy




More information about the Python-list mailing list