Professional Documents
Culture Documents
Class Activity-VI
Variable Arguments
1. Write a function mean that takes a variable number of integers as input and
returns their mean (average) as a float.
2. Write a function concatenate that takes a variable number of strings as input
and returns a single string that is the concatenation of all the input strings.
3. Write a function intersection that takes two or more lists as input and returns
a list that contains only the elements that are present in all the input lists.
4. Write a function max_diff that takes a variable number of integers as input and
returns the maximum difference between any two of the input integers.
5. Write a function flatten that takes a variable number of lists as input and
returns a single list that contains all the elements from all the input lists.
Lambda
1. Write a lambda function that takes a list of integers as input and returns a list
of the squares of those integers.
2. Write a lambda function that takes a list of strings as input and returns a list of
the lengths of those strings.
3. Write a lambda function that takes a list of tuples as input, where each tuple
contains two integers, and returns a list of the products of those integers.
4. Write a lambda function that takes a list of dictionaries as input, where each
dictionary contains a "name" key and an "age" key, and returns a list of the
names of people who are under 18 years old.
5. Write a lambda function that takes a string as input and returns a new string
where every other character is capitalized. For example, "hello world" should
become "hElLo wOrLd".
6. Write a lambda function that takes a list of integers as input and returns a new
list with only the even numbers from the input list.
7. Write a lambda function that takes a list of strings as input and returns a new
list with only the strings that start with the letter "a".
8. Write a lambda function that takes a list of dictionaries as input, where each
dictionary contains a "name" key and an "email" key, and returns a new list
with only the dictionaries that have a Gmail email address.
9. Write a lambda function that takes a list of integers as input and returns the
product of all the numbers in the list.
10.Write a lambda function that takes a string as input and returns a new string
with all the vowels removed.
Lambda with map()
1. Write a lambda function that takes a list of integers as input and returns a new
list with each integer increased by 1.
2. Write a lambda function that takes a list of strings as input and returns a new
list with each string in all caps.
3. Write a lambda function that takes a list of dictionaries as input, where each
dictionary contains a "name" key and an "age" key, and returns a new list with
the ages of each person increased by 1.
4. Write a lambda function that takes a list of integers as input and returns a new
list with only the numbers that are greater than 5.
5. Write a lambda function that takes a list of strings as input and returns a new
list with the length of each string.