In this example, i’ll show you how to filter the positive numbers from a list.
Python Code:
1 2 3 4 5 6 |
nums = [-15, 12, 15, -5] print("Original numbers in the list: ",nums) Pos_nums = list(filter(lambda x: x >0, nums)) print("Positive numbers in the list: ",Pos_nums) |
Output: