Created
March 22, 2016 22:38
-
-
Save dmahugh/c45362ef8a74f53f3f6d to your computer and use it in GitHub Desktop.
Python function to remove URL bloat from JSON returned by GitHub V3 API
This file contains 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
def remove_github_urls(dict_in): | |
"""Remove URL entries (as returned by GitHub API) from a dictionary. | |
1st parameter = dictionary | |
Returns a copy of the dictionary, but with no entries named *_url or url. | |
""" | |
return {key: dict_in[key] for key in dict_in if \ | |
not key.endswith('_url') and not key == 'url'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The JSON returned by most calls to the GitHub V3 API is an order of magnitude larger than it needs to be, because it contains all of the endpoints for other related queries you might want to do next. This one-liner uses a Python dictionary comprehension to get rid of all that extra stuff.