List filtering: simpler one line statement?
I have a list of values which I need to filter given the values in a list
of booleans:
list_a = [1, 2, 4, 6]
filter = [True, False, True, False]
I generate a new filtered list with the following line:
filtered_list = [i for indx,i in enumerate(list_a) if filter[indx] == True]
The line works but looks (to me) a bit overkill and I was wondering if
there was a simpler way to achieve the same.
No comments:
Post a Comment