Quantcast
Channel: How to mask a list using boolean values from another list - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by Jeka Golovachev for How to mask a list using boolean values from...

If already have you some function that returns True/False for each element y, use filter(), example:list(filter(lambda x: x < 'c' , y))Ormy_iter = iter([True, False, True, False])list(filter(lambda...

View Article



Answer by tdurnford for How to mask a list using boolean values from another...

There are several ways to do this. The simplest way would be to zip the two lists together and use a list comprehension to keep the items you want. x = [True, False, True, False]y = ['a', 'b', 'c',...

View Article

Answer by eapetcho for How to mask a list using boolean values from another list

This is rather simple to solve. Consider writing properly your list:x = [True, False, True, False]y = [a, b, c, d] # assuming that a, b, c and d are some kind of objectoutput = []for i, k in...

View Article

Answer by sacuL for How to mask a list using boolean values from another list

I think the easiest way is to use numpy:import numpy as np>>> x = [True, False, True, False]>>> y = ['a', 'b', 'c', 'd']>>> np.array(y)[x]array(['a', 'c'],...

View Article

Answer by ggorlen for How to mask a list using boolean values from another list

You can use zip and a list comprehension to perform a filter operation on y based on corresponding truth values in x:x = [True, False, True, False]y = ["a", "b", "c", "d"]print([b for a, b in zip(x, y)...

View Article


How to mask a list using boolean values from another list

I have a list like this:x = [True, False, True, False]and a list like this:y = [a, b, c, d]I would like to mask x over y to get this output:output = [a, c]I know how to do this using while/for loops,...

View Article
Browsing all 6 articles
Browse latest View live




Latest Images