17. Create a dictionary 'ODD' of odd numbers between 1 and 10, where the key is the decimal number and
the value is the corresponding number in words.
1. Display the keys in dictionary 'ODD'
2. Display the values in dictionary "ODD'
3. Display the items from dictionary 'ODD'
4. Find the length of the dictionary "ODD'.
5. Retrieve the value corresponding to the key 9
6. Delete the item from the dictionary, corresponding to the key 9
Answers
Answered by
7
#creating the dictionary
>>> ODD = {1.0:"One", 3.0:"Three", 5.0:"Five", 7.0:"Seven", 9.0:"Nine"}
#1
>>> ODD.keys()
#2
>>> ODD.values()
#3
>>>ODD.items()
#4
>>> len(ODD)
#5
>>> ODD.get(9)
#6
>>> ODD.pop(9)
- keys() is a method that retrieves the keys of a dictionary in the form of a list.
- values() is a method that retrieves the values from a dictionary in the form of a list.
- items() is a method that retrieves the keys and values, each key-value being in a tuple and all the tuples in the form of a list.
- len() is a function that calculates the length.
- get() is a method the retrieves the value of the specified key/prints an optional message if the key isn't in the dictionary.
- pop() is a method that removes the specified key from the dictionary and returns its value.
Answered by
0
Answer:
python program
Explanation:#creating the dictionary
>>> ODD = {1.0:"One", 3.0:"Three", 5.0:"Five", 7.0:"Seven", 9.0:"Nine"}
#1
>>> ODD.keys()
#2
>>> ODD.values()
#3
>>>ODD.items()
#4
>>> len(ODD)
#5
>>> ODD.get(9)
#6
>>> ODD.pop(9)
Similar questions