Dictionary Ws - 06102023 - 140518

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

The Pioneer School-(CBSE)

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

The Pioneer School-(CBSE)


Worksheet-2(10/10/2023)
Grade:XI Subject: Computer Science
1.Dictionaries are ............... set of elements.
1. sorted
2. ordered
3. unordered
4. random

2.Dictionaries are also called ...............

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

6.What will be the output?

dictionary ={1:"geek", 2:"for", 3:"geeks"}


del dictionary

1. del deletes the entire dictionary


2. del doesn’t exist for the dictionary
3. del deletes the keys in the dictionary
4. del deletes the values in the dictionary
7.What will be the output?

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?

test = {1:'A', 2:'B', 3:'C'}


del test[1]
test[1] = 'D'
del test[2]
print(len(test))

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. {‘b’: [2], ‘a’: 1}


2. {‘a’: 1, ‘b’: [2, 3, 4]}
3. {‘b’: [2], ‘a’: [3]}
4. Error
3.The key can be considered as an index into the dictionary. (True/False)
4.Which of the brackets are used to define the dictionary?

1. Round Bracket ()
2. Square Bracket []
3. Curly Bracket {}
4. Angular Bracket <>

5.The key and value is separated by ___________ symbol in the dictionary.

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.

7.Which of the following is correct declaration of empty dictionary A?


a) A = []
b) A = ()
c) A = {}
d) A = <>

The Pioneer School-(CBSE)


Worksheet-5(13/10/2023)
Grade:XI Subject: Computer Science

1.Write the output of following code:


x = {1:10, 2:20, 3:30}
x[2]=25
print(x)
2.Write the output of following code:
x = {1:10, 2:20, 3:30}
x[4] = 20
print(x)
3.Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for k in d.keys():
print (k, '=', d[k])
4.Write the output of following code:
x = {1:10}
d = {2:20, 3:30, 4:40}
x.update(d)
print(x)
5.Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
a = d.setdefault('z',4)
print(a)
a = d.setdefault('w',0)
print(a)

You might also like