Reputation: 1
Suppose we have a list of integers L in python, and a function F which takes in an integer and returns a boolean. I have the following code:
for i in L:
if F(i):
do_whatever(i)
is there a way of doing this in one line in python, or rather, a more pythonic approach?
Upvotes: 0
Views: 77
Reputation: 3221
Using the built-in python functions:
map(do_whatever, filter(F, L))
Upvotes: 1