Comparing two types of lists in Python

Question:

I have two lists J and Cond. I want to compare these lists and print corresponding values in J for False in Cond. Is there equivalent of np.where()? I present the expected output.

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

The expected output is

J=[1,4,7]
Asked By: jcbose123

||

Answers:

You can use the zip builtin:

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

Which results in:

[1, 4, 7]
Answered By: no_hex

you can do:

[j for j, cond in zip(J[0], Cond) if not cond]
Answered By: Wiliam
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.