reduce expression to test sublist

Dave Angel d at davea.name
Sat Jan 5 23:05:20 CET 2013


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) - 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.
>

Thanks.  I wasn't aware that sets supported ordered comparison that way,
though it makes perfect sense now that you point it out.


-- 

DaveA




More information about the Python-list mailing list