Professional Documents
Culture Documents
Dictionary Ws - 06102023 - 140518
Dictionary Ws - 06102023 - 140518
Dictionary Ws - 06102023 - 140518
Worksheet-1(9/10/2023)
Grade:XI Subject: Computer Science-(Dictionary)
1.Find the incorrect statement/s out of the following:
a) >>> dict1= {'A': 'Apple', 'B':'Boy', 'C':'Cat', 'D':'Dog'}
b) >>>print (dict1[‘a’] )
c) >>> print (dict1[‘B’] )
d) >>> print (dict1[‘Cat’] )
e) >>> prin t(dict1[‘E’] )
2.Consider the following dictionary:
states=['D':'Delhi', 'K':'Kerala', 'T':'Tamil Nadu', 'B':'Bihar']
Write Python statements for the following. Kindly state the reason for the operations which
not possible.
a) To insert (‘R’:“Red Fort”) and (‘J’:“Jantar Mantar”) in the dictionary states
b) To replace the value of key ‘K’ by ‘Karnataka’.
c) To remove the element with key ‘B’.
d) To delete the dictionary, states.
e) To return a sorted list of keys in the dictionary, states
f) To check whether the element with key ‘D’ is present in the dictionary or not.
g) To display all elements of a dictionary states in different lines.
3.Which of the following types qualify to be the keys of a dictionary?
1. String
2. tuple
3. Integer
4. float
5. list
6. dictionary
1. mappings
2. hashes
3. associative arrays
4. all of these
3.Dictionaries are ............. data types of Python.
1. mutable
2. immutable
3. simple
4. all of these
4.Which of the following functions will return the key, value pairs of a dictionary ?
1. keys( )
2. values( )
3. items( )
4. all of these
5.Which of the following will add a key to the dictionary only if it does not already exist in
the dictionary ?
1. fromkeys( )
2. update( )
3. setdefault( )
4. all of these
a = {}
a[1] = 1
a['1'] = 2
a[1]= a[1]+1
count = 0
for i in a:
count += a[i]
print(count)
The Pioneer School-(CBSE)
Worksheet-3(11/10/2023)
Grade:XI Subject: Computer Science
1. What will be the output?
1. 2
2. 1
3. 0
4. Error
2.What will be the output?
a ={}
a['a']= 1
a['b']=[2, 3, 4]
print(a)
1. Round Bracket ()
2. Square Bracket []
3. Curly Bracket {}
4. Angular Bracket <>
5. Comma ,
6. Semi-Colon ;
7. Dash –
8. Colon :
The Pioneer School-(CBSE)
Worksheet-4(12/10/2023)
Grade:XI Subject: Computer Science
1. Which is the correct form of declaration of dictionary?
a) day = {1: 'm', 2: 't', 3: 'w'}
b) day = (1; 'm', 2; 't', 3; 'w')
c) day = [1: 'm', 2: 't', 3: 'w']
d) day = {1 'm', 2 't', 3 'w'}
2.Merge two Python dictionaries into one
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
dict2 = {'Thirty': 30, 'Fourty': 40, 'Fifty': 50}
dict3 = {**dict1, **dict2}
print(dict3)
3. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are
Jan, Feb and Mar respectively.
4.Write the two ways to construct an empty dictionary.
5.Write the output of following code:
sales = {'Audi':45, 'BMW':32, 'Ferrari':12}
for x in sales:
print(x)
6.Suppose a dictionary days is declared as:
days={1:"Sun", 2:"Mon", 3:"Wed"}
Write a statement in Python to change Wed to Tue.