You are on page 1of 3

UNIVERSITY OF PETROLEUM AND ENERGY STUDIES

Class Activity-VI

Program Name: B. Tech CS Semester: II


Course Name : Python Programming Max. Marks: 100
Course Code: CSIB1002
Start Date: Due Date:

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.

Variable Key-Value Arguments


1. Write a function print_info that takes any number of keyword arguments as
input and prints out each key-value pair on a new line in the format "key:
value".
2. Write a function combine_dicts that takes any number of dictionaries as input
and returns a new dictionary that is the combination of all the input
dictionaries.
3. Write a function count_values that takes any number of arguments as input
and returns a dictionary where the keys are the input values and the values
are the number of times that value appears in the input.
4. Write a function sort_by_key that takes any number of dictionaries as input
and returns a list of the input dictionaries sorted by their keys in alphabetical
order.
5. Write a function calculate_average that takes any number of dictionaries as
input, where each dictionary has a key "score" with a numerical value, and
returns the average of all the scores.

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.

Lambda with filter()


1. 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.
2. Write a lambda function that takes a list of strings as input and returns a new
list with only the strings that contain the letter "a".
3. 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.
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 only the strings that are at least 5 characters long.

You might also like