Last active
September 13, 2022 12:02
-
-
Save narenaryan/1668d1d0628992cd3280c70eb5761604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "languages": { | |
| "python": { | |
| "name": "Python", | |
| "author": "Guido Van Rossum", | |
| "usedFor": ["Scripting", "Web Development", "Text processing", "Data Science"] | |
| }, | |
| "go": { | |
| "name": "Go", | |
| "author": "Google", | |
| "usedFor": ["Devops Tooling", "Low-latency Servers", "command-line Tools"] | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| # Open a file pointer | |
| fp = open("data.json", "r") | |
| # Decoded result | |
| result = json.load(fp) | |
| languages = result.get("languages") | |
| if languages: | |
| golang = languages.get("go") | |
| if golang: | |
| name = golang.get("name") | |
| count = len(golang.get("usedFor")) | |
| # Prints 'Go is mainly used for 3 reasons' | |
| print(f"{name} is mainly used for {count} reasons") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment