Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Exercise Questions on Set

1. Write a Python program to declare and initialize a set and perform following operations on them.

a. To iterate over set elements by using for-each loop.


b. To add member(s) to a set.
c. To remove item(s) from a given set.
d. To remove an item from a set if it is present in the set.
e. To print length (numbers of elements) in the set.
f. To find the smallest and largest element from set.
g. To remove all elements from set
h. To check presence of an element in Set

2. Declare and initialize two sets and perform following operations on them.
a. To create set difference.
b. To create a symmetric difference.
c. To print common elements between them
d. To obtain the values which are in set-A but not in set-B
e. To check whether they have any common element between them or not

3. Consider following set of Strings and print the String which has largest length among them.
{“Mahabaleshwar”, “Pune”, “Mumbai”, “Bangalore”, “Chennai”, “Vishakhapatnam”, “Kochi”}

4. Consider above set of String and prepare a list containing only length of each city names.
Expected output: [13, 4, 6, 9, 7, 14, 5]

5. Consider above set of Strings and prepare a dictionary containing {city_name : length} as key:value pairs.

You might also like