python 找到列表中满足某些条件的元素

a = [0, 1, 2, 3, 4, 0, 2, 3, 6, 7, 5]

selected = [x for x in a if x in range(1, 5)]   # 找到a中属于[1,5)中的元素

print (selected)

我也是第一次碰到这样的操作。

原文地址:https://www.cnblogs.com/star12111/p/8832244.html