小编std*_*dmn的帖子

根据父列表将值分组到列表中

我有一个列表,我试图将其与其他两个列表中的值的顺序组合进行比较。下面的代码有效,但输出值位于单个平面列表中。

values = [3,6,7,8]
list1 = [2,5]
list2 = [4,8]
main = []

for i in values:
    for x,y in zip(list1, topElevation):
        if x<i<y:
            main.append(i)
>>>[3,6,7]
Run Code Online (Sandbox Code Playgroud)

如何组织脚本,以便将值拆分为多个列表,以便第一个嵌套列表采用list1[0]<i<list2[0]、第二个list1[1]<i<list2[1]等等的所有值...(通过list1[n]<i<list2[n])?在这种情况下,输出将是:

>>>[[3],[6,7]]
Run Code Online (Sandbox Code Playgroud)

python nested list python-2.x python-2.7

3
推荐指数
1
解决办法
86
查看次数

标签 统计

list ×1

nested ×1

python ×1

python-2.7 ×1

python-2.x ×1