Selecting a subset of integers given two lists of end points

与世无争的帅哥 提交于 2020-01-05 05:52:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!