问题
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,14,22,23,24,25]
Thank you guys in advance
回答1:
You can use a nested list commprehension:
[i for a, b in zip(t1, t2) for i in range(a, b + 1)]
来源:https://stackoverflow.com/questions/55877743/selecting-a-subset-of-integers-given-two-lists-of-end-points