Skip to content Skip to sidebar Skip to footer

Selecting A Subset Of Integers Given Two Lists Of End Points

I have two lists of end points that look like this: t1 = [0,13,22] t2 = [4,14,25] I am looking for the most efficient way to generate an output that looks like this: [0,1,2,3,4,13

Solution 1:

You can use a nested list commprehension:

[i for a, b in zip(t1, t2) for i in range(a, b + 1)]

Post a Comment for "Selecting A Subset Of Integers Given Two Lists Of End Points"