0
0
Pythonprogramming~15 mins

Lambda with filter() in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Filter Even Numbers Using Lambda
๐Ÿ“– Scenario: Imagine you have a list of numbers representing daily sales counts. You want to find only the even sales numbers to analyze patterns.
๐ŸŽฏ Goal: Build a small program that uses a lambda function with filter() to select even numbers from a list.
๐Ÿ“‹ What You'll Learn
Create a list called sales with exact numbers: 12, 7, 9, 20, 15, 8
Create a lambda function inside filter() to select even numbers
Store the filtered result as a list called even_sales
Print the even_sales list
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Filtering data like sales numbers helps businesses focus on specific patterns, such as even or odd counts, which can be important for inventory or promotions.
๐Ÿ’ผ Career
Understanding how to use lambda with filter() is useful for data cleaning and processing tasks common in data analysis and software development.
Progress0 / 4 steps
1
Create the sales list
Create a list called sales with these exact numbers: 12, 7, 9, 20, 15, 8.
Python
Need a hint?

Use square brackets [] to create the list and separate numbers with commas.

2
Prepare to filter even numbers
Create a variable called even_sales and assign it the result of filter() using a lambda function that checks if a number is even (divisible by 2) applied to the sales list.
Python
Need a hint?

The lambda function should take one argument and return True if the number is even.

3
Convert filter object to list
Convert the filter object even_sales to a list by wrapping it with list() and reassign it back to even_sales.
Python
Need a hint?

Use list() to turn the filter result into a list you can print.

4
Print the even sales list
Print the even_sales list to display the filtered even numbers.
Python
Need a hint?

Use print(even_sales) to show the result.