Unit – II: Data Structures in Python - Tutorial Sheet
SECTION A: Very Short Answer Questions (1 Mark Each)
Lists
1. What is a list in Python?
2. Give an example of a list.
3. How do you access the first element of a list?
4. Which symbol is used for list indexing?
5. Write any one list method.
Tuple
6. What is a tuple?
7. Give an example of a tuple.
8. List any one difference between list and tuple.
9. How do you access an element in a tuple?
10. Name any tuple method.
Set
11. Define a set.
12. Can sets store duplicate values?
13. Write an example of a set.
14. Which method is used to add an element to a set?
15. What is the use of remove() in sets?
Dictionary
16. What is a dictionary?
17. What are keys used for in a dictionary?
18. Write an example of a dictionary.
19. How do you delete a key-value pair?
20. Name any dictionary method.
SECTION B: Short Answer Questions (2–3 Marks Each)
Lists
1. Write rules for defining a list with examples.
2. Explain any four basic list operations.
3. Write any four list methods with examples.
4. How can you update and delete list values? Explain with code.
Tuple
5. Explain how to define a tuple with two examples.
6. Write any three tuple operations.
7. Write any three built-in tuple functions/methods.
Set
8. Explain any four basic set operations.
9. Write examples of adding and removing elements from a set.
10. List and explain any three set methods.
Dictionary
11. Explain how to define a dictionary with two examples.
12. What are basic dictionary operations? Explain any three.
13. Write any four dictionary methods with examples.
SECTION C: Output Prediction (2 Marks Each)
1.
lst = [10, 20, 30]
print(lst[1])
2.
t = (1, 2, 3, 4)
print(t[-1])
3.
s = {1, 2, 3}
[Link](4)
print(s)
4.
d = {"a": 10, "b": 20}
print(d["b"])
5.
lst = [1, 2, 3]
[Link](4)
print(len(lst))
SECTION D: Correct the Errors (3 Marks Each)
1.
lst = (1, 2, 3)
lst[0] = 10
2.
t = [1, 2, 3]
print(t[3])
3.
s = {1, 2, 3}
[Link](4)
4.
d = {"id":101, "name":"Ravi"}
print(d[0])
5.
lst = [10,20,30]
del lst
print(lst)
SECTION E: Programming Questions (5–6 Marks Each)
Lists
1. Write a program to input 5 numbers and store them in a list. Print
the sum and average.
2. Write a program to find the largest and smallest value in a list.
3. Write a program to remove all even numbers from a list.
Tuple
4. Create a tuple and print the count of a given element.
5. Write a program to convert a list into a tuple.
Set
6. Write a program to perform union, intersection, and difference of
two sets.
7. Write a program to check whether an element exists in a set.
Dictionary
8. Write a program to store student details in a dictionary (name, roll,
branch) and print the values.
9. Write a program to update the marks of a student in a dictionary.
10. Write a program to count the occurrence of each character in
a word using a dictionary.
SECTION F: Application-Based Questions (Higher Level)
1. Write a program to remove duplicate elements from a list using sets.
2. Write a program to convert two lists into a dictionary (keys list +
values list).
3. Write a program to merge two dictionaries.
4. Write a menu-driven program to perform the following using a list:
o Add element
o Delete element
o Search element
o Display list