Python OrderedDict access and existence check
Write a Python program that accesses an item in the OrderedDict by its key. Check if a specified item exists in the OrderedDict as well.
Sample Solution:
Code:
Output:
Quantity of Desktops: 45 Mobile exists in the OrderedDict Charger does not exist in the OrderedDict
In the exercise above, we use 'square brackets' to access an item in the OrderedDict using its key ('Desktop'). We also use the 'in' keyword to check if a specified item ('Mobile' / 'Charger') exists in the OrderedDict.
Flowchart:
Previous: Python OrderedDict sorting: Keys and values.
Next: Python OrderedDict Reversal.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics