【问题标题】:range of data in a list based on the index of the values in another list基于另一个列表中值的索引的列表中的数据范围
【发布时间】:2018-01-18 08:09:06
【问题描述】:

我正在尝试根据另一个列表中值的索引打印列表中的一系列数据:

d=[10, 14, 18, 30, 40]
s=[2, 4, 5, 6, 7]    
print (s[d.index(d>=14)])

我得到 TypeError: '>=' not supported between 'list' 和 'int' 的实例。这是我在大代码中遇到的简化问题。我该如何解决?谢谢。

【问题讨论】:

    标签: list


    【解决方案1】:
    d = [10, 14, 18, 30, 40]
    s = [2, 4, 5, 6, 7]
    
    print([s[d.index(item)] for item in d if item > 14])
    #print [5, 6, 7]
    

    我想你可能想要上面的东西?

    【讨论】:

      猜你喜欢
      • 2023-01-02
      • 1970-01-01
      • 2017-06-07
      • 2020-11-15
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 2021-07-14
      • 2015-05-24
      相关资源
      最近更新 更多