Advanced Conditionl Statement Pyhton
Advanced Conditionl Statement Pyhton
1. List comprehension
3. Lambda Operator
4. Filter
5. Reduce
6. Map
7. Recursive Func on
Basic Structure:
Using a loop:
Output:-
Basic Structure:
Examples:
Using a loop:
Output :-
Output :-
2. Crea ng a Dic onary with Squared Values
Output :-
Basic Structure:
lambda: Keyword to define the func on.
Basic Syntax:
Func on: A func on that returns True or False for each element.
You can also try with other func ons like map(),sorted()
Basic Syntax:
Func on: A func on that takes two arguments and reduces the iterable to a single value.
Basic Syntax:
1. Use list comprehension to generate a list of numbers from 1 to 20 that are divisible
by 4.
2. Create a dic onary comprehension where keys are numbers from 1 to 5, and values
are their squares.
3. Write a lambda func on to check if a given number is even.
4. Use map() with a lambda func on to double each number in a given list [2, 4, 6, 8].
5. Use filter() with a lambda func on to extract words star ng with 'b' from the list
["apple", "banana", "berry", "grape"].
6. Use reduce() to find the sum or product of all elements in the list [1, 2, 3, 4, 5].
7. Implement a recursive func on to calculate the factorial of a number.
Bonus:
Modify the recursive func on to compute the Fibonacci sequence for n terms.