Python JSON: Access only unique key value of a Python object
Python JSON: Exercise-9 with Solution
Write a Python program to access only unique key value of a Python object.
Sample Solution:-
Python Code:
import json
python_obj = '{"a": 1, "a": 2, "a": 3, "a": 4, "b": 1, "b": 2}'
print("Original Python object:")
print(python_obj)
json_obj = json.loads(python_obj)
print("\nUnique Key in a JSON object:")
print(json_obj)
Output:
Original Python object: {"a": 1, "a": 2, "a": 3, "a": 4, "b": 1, "b": 2} Unique Key in a JSON object: {'a': 4, 'b': 2}
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to check whether a JSON string contains complex object or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-json-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics