More than one key can have the same value
The values of the dictionary can be accessed as dict[key]
Values of a dictionary must be unique
Values of a dictionary can be a mixture of letters and numbers
What will be the output of the following Python code snippet?
>>> a={1:"A",2:"B",3:"C"} >>> del a
method del doesn’t exist for the dictionary
del deletes the values in the dictionary
del deletes the entire dictionary
del deletes the keys in the dictionary
Removes an arbitrary element
Removes all the key-value pairs
Removes the key-value pair for the key given as an argument
Invalid method for dictionary
total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))
3
1
2
0
a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)
4
Error, the keys can’t be a mixture of letters and numbers
numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb)
Error, dictionary in a dictionary can’t exist
‘Numbers’: {1: 56, 3: 7}
{‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
{‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))
None
An exception is thrown
test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))
Error as the key-value pair of 1:’A’ is already deleted
a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) print(a)
6
a={} a['a']=1 a['b']=[2,3,4] print(a)
Exception is thrown
{‘b’: [2], ‘a’: 1}
{‘b’: [2], ‘a’: [3]}
{'a': 1, 'b': [2, 3, 4]}
What will be the output of the following Python code?
count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)
25
17
16
Tuples can’t be made keys of a dictionary
a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])
[2,3,4]
a={'B':5,'A':9,'C':7} print(sorted(a))
[‘A’,’B’,’C’]
[‘B’,’C’,’A’]
[5,7,9]
[9,5,7]
Returns True if any key of the dictionary is true
Returns False if dictionary is empty
Returns True if all keys of the dictionary are true
Method any() doesn’t exist for dictionary
a=dict() a[1]
An exception is thrown since the dictionary is empty
‘ ‘
seed()
sqrt()
factorial()
print()
What will be the output of the following Python expression?
print(round(4.576))
4.5
5
4.6
(x**y)**z
(x**y) / z
(x**y) % z
(x**y)*z
What will be the output of the following Python function?
all([2,4,0,6])
Error
True
False
round(4.5676,2)?
4.57
4.56