【问题标题】:Comparing two types of lists in Python在 Python 中比较两种类型的列表
【发布时间】:2023-01-13 19:59:48
【问题描述】:

我有两个列表 JCond。我想比较这些列表并在J中为False打印相应的值Cond。有没有等同于np.where()?我提出了预期的输出。

J=[[1,2,4,6,7]]
Cond = [False, True, False, True, False]

预期的输出是

J=[1,4,7]

【问题讨论】:

    标签: python list


    【解决方案1】:

    您可以使用内置的 zip

    J = [zipped_val[0] for zipped_val in zip(J[0], Cond) if not(zipped_val[1])]
    print(J)
    

    结果是:

    [1, 4, 7]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多