How to use list comprehension on function with conditions in Python

1 Answer

0 votes
def f(n):
  return n * 4

lst = [f(n) for n in range(20) if n % 3 == 0]

print(lst)



'''
run:

[0, 12, 24, 36, 48, 60, 72]

'''

 



answered Aug 22, 2019 by avibootz
...