Python: filter list
28 May 2023 (Updated 28 May 2023)
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_nums = filter(lambda x: x % 2 == 0, nums)
odd_nums = filter(lambda x: x % 2 == 1, nums)
print(list(even_nums))
print(list(odd_nums))
Tagged:
Python
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment