Jun-11-2019, 10:18 AM
(This post was last modified: Jun-11-2019, 10:21 AM by khalidreemy.)
Hello
I have two lists X and Y as follows:
So Z should be equals:
Z = ['A','C','D']
I tried the following code but it is not giving the proper output
How to create the Z list using list comprehension ?
I have two lists X and Y as follows:
X = ['A','B','C','D','E'] Y = [ 1 , 0 , 1 , 1 , 0 ]Here I need to create a new list Z that contains elements from X if the corresponding value in Y = 1.
So Z should be equals:
Z = ['A','C','D']
I tried the following code but it is not giving the proper output
Z = [X[i] for i in Y if Y[i] == 1]but the result is not correct.
How to create the Z list using list comprehension ?