Informatics Practices
Suppose
>>> d1 = { 1 : 'one' , 2: 'two' , 3: 'three' , 4: 'four'}
>>> d2 = { 5 :'five', 6:'six' }
Write the output of the following code:
>>> d1.items()
>>> d1.keys()
>>> d1.values()
>>> d1.update(d2)
>>> len(d1)
Python Dictionaries
5 Likes
Answer
dict_items([(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')])
dict_keys([1, 2, 3, 4])
dict_values(['one', 'two', 'three', 'four'])
6
Working
d1.items()— Returns a list of tuples containing the key-value pairs ind1.d1.keys()— Returns a list of all the keys ind1.d1.values()— Returns a list of all the values ind1.d1.update(d2)— Updatesd1with key-value pairs fromd2. After this operation,d1contains {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six'}.len(d1)— Returns the number of key-value pairs ind1, which is 6 after updating.
Answered By
1 Like
Related Questions
Find errors and rewrite the same after correcting the following code:
d1.len()Find errors and rewrite the same after correcting the following code:
d1.clears()Suppose
>>> d1 = { 1 : 'one' , 2: 'two' , 3: 'three' , 4: 'four'} >>> d2 = { 5 :'five', 6:'six' }Write the output of the following code:
>>> del d1[3] >>> print(d1) >>> d1.pop(4) >>> print(d1) >>> d1 [8] =' eight' >>> print(d1) >>> d1.clear() >>> print(d1)Write a Python program to find the highest 2 values in a dictionary.