You are on page 1of 4



ASSIGNMENT 9 LESSON 10: Tuples and Dictionary


NOTE: Write this in the Classwork with the answers.
Write the lesson name and start writing the assignment

1. Write a single statement to add a single item in a tuple.


2. What is the length of the tuple shown below? T = ((((„a‟, 1), ‟b‟, ‟c‟), ‟d‟, 2), ‟e‟, 3)
3. If a is (1, 2, 3), what is the difference (if any) between a*3 and [a, a, a]?
4. If a is (1, 2, 3), is a *3 equivalent to a + a + a?
5. If a is (1, 2, 3), what is the meaning of a [1:1] = 9?
6. What is the difference between (30) and (30,)?
7. Write a python program to display all the elements of the following tuple except ‘d’
T = ((((„a‟, 1), ‟b‟, ‟c‟), ‟d‟, 2), ‟e‟, 3)
8. T1=(“RIVER CAUVERY”,[1,2,’3’],’S’,(3,4,6),”KRISHNA”,10)
I) T1[1][1]
II) 10 in T1
III) 50 not in T1
IV) T1[4][3]
V) T1[1][2]*3
VI) T1[-5:-3]+T1[3]
VII) T1[0]+T1[2]
VIII) T1[4:4]
9. Write a Python program to combine first 3 elements and last 3 elements from a tuple.
T2=(‘a’,1,2,3,4,’b’,’c’,’Ram’,10)
10.Suppose,
D1={1:”CHENNAI”,2:”BANGALORE”,3:”HYDERABAD”,4: “MUMBAI”,
5:“GUJARAT”, 6: “DELHI”}
D2={7:”PUNJAB”, 8:”HARYANA”,9:”KERALA”}
Write the output of the following code:
a) >>>D1.items()
b) >>>D1.keys()
c) >>>D1.values()
d) >>>D1.update(D2)
e) >>>len(D1)
f) >>>del D1[3]
g) >>>print(D1)
h) >>>D1.pop(4)
i) >>>print(D1)
j) >>>D1[11]=”ALLAHABAD”
k) >>>print(D1)
l) >>>D1.clear()
m) >>>print(D1)

COMPUTER SCIENCE LESSON 10: Tuples and Dictionary


NOTE: Copy the questions alone in your classwork.
1. What do you understand by immutability?
2. What is a tuple?
3. What are the differences between lists and tuples when both are sequences?
4. What is the similarity between strings and tuples?
5. Does a slice operator always produce a new Tuple?
6. How is an empty Tuple created?
7. How is a tuple containing just one element created?
8. Can tuples be nested? Give an example
9. Discuss the utility and significance of Tuples.
10. How can you say that a tuple is an ordered list of objects?
11. How can you add an extra element to a tuple?
12. Explain the tuples operations in detail.
13. Tuples can be used as keys in Python Dictionaries. True or False?
14. Tuple is an ordered immutable sequence of objects. Justify your answer.
15. What is meant by nested tuples? Illustrate it with an example
16. Find out the output generated by following code fragments:
plane = (“Passengers”, ”Luggage”)
plane [1] = “Snakes”
a) (a, b, c) = (1,2,3)
b) (a, b, c, d) = (1,2,3)
c) a, b, c, d = (1,2,3)
d) a, b, c, d, e = (p, q, r, s, t) = t1

17.

18. WAP that creates a tuple storing first 9 items of Fibonacci Series.
19. WAP that creates a third tuple after adding two tuples. Add second after first tuple.
20. WAP to calculate the mean of the numbers of the tuple.
21. WAP to calculate the average of the numbers of the tuple.

DICTIONARY
1. What is a dictionary?
2. What are the differences between lists and dictionary?
3. Can list be used as a key to dictionary? State yes or no. Justify.
4. Can you change the order of the dictionaries contents?
5. What is a key value pair in dictionary?
6. Can you modify the keys and values in a dictionary?
7. How will you create a dictionary?
8. “Dictionaries are mutable”. Justify
9. Explain the operations of Dictionary.
10. Discuss the utility and significance of Dictionaries
11. Why is a dictionary termed as an unordered collection of objects?
12. How is clear() function different from del Statement?
13. What is the output produced by the following code –

14.
15. Write a program to accept values from the user. Add a tuple to it and display its
element one by one. Also display its maximum and minimum values.
16. Write a program to store student names and their phone numbers to store it in a
dictionary and print the phone number of a particular name.
17. WAP that repeatedly asks the user to enter product names and prices. Store all of them
in a dictionary whose keys are product names and values are prices. And also write a
code to search an item from the dictionary.
18. WAP to create a dictionary named year whose keys are month names and values are
their corresponding number of days.

***********

You might also like