How to identify which numbers in a list are within each others' range

Boris Borcic bborcic at gmail.com
Fri Feb 8 15:08:33 CET 2008


Boris Borcic wrote:
> Arnaud Delobelle wrote:
> (...)
>>
>> from itertools import chain
>>
>> def overlaps(lst):
>>     bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst)))
> 
> imho, this is a uselessly painful equivalent of
> 
>       bounds = ((x[k],i) for i,x in enumerate(lst) for k in (1,2))

even more readable :

         bounds = ((bound(x),i) for bound in (min,max) for i,x in enumerate(lst))



More information about the Python-list mailing list