This module introduces functional programming concepts in Python, including lambda functions, closures, iterators, generators, decorators, and comprehensions.
- Solution
- Description:
Task "Apply All Functions at Once":
- Implement the
apply_all_func
function that takes a list of numbers and an arbitrary number of functions, applying each function to the list and returning a dictionary with function names as keys and their results as values.
- Implement the
- Solution
- Description:
- Create list and dictionary comprehensions to filter and pair elements based on string lengths, and to create a dictionary with string lengths for strings with an even length.
- Solution
- Description:
- Implement generator expressions to calculate differences in string lengths from two lists
and to compare string lengths at the same positions without using
zip
.
- Implement generator expressions to calculate differences in string lengths from two lists
and to compare string lengths at the same positions without using
- Solution
- Description:
Task "Functional Diversity":
- Write a lambda function to compare character matches in two strings. Implement a closure
that returns a function for writing multiple data types to a file.
Also, create a class with the
__call__
method that randomly returns words from a collection.
- Write a lambda function to compare character matches in two strings. Implement a closure
that returns a function for writing multiple data types to a file.
Also, create a class with the
- Solution
- Description:
Task "Range Is Simple":
- Create an iterator class that behaves similarly to Python's
range()
function but allows for step validation. Implement custom error handling for invalid steps.
- Create an iterator class that behaves similarly to Python's
- Solution
- Description:
- Write a generator function
all_variants
that returns all subsequences of a given string during iteration.
- Write a generator function
- Solution
- Description:
- Implement a decorator function that checks whether the result of another function (which sums three numbers) is a prime number, printing "Prime" or "Composite" based on the result.