Skip to content

Instantly share code, notes, and snippets.

@csarigoz
Created July 4, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csarigoz/83ee16068300b753f022d716f1a6b346 to your computer and use it in GitHub Desktop.
Save csarigoz/83ee16068300b753f022d716f1a6b346 to your computer and use it in GitHub Desktop.
Filter a List of Dictionaries By Key
users = [{'username': 'alice', 'age': 23, 'play_time': 101},
{'username': 'bob', 'age': 31, 'play_time': 88},
{'username': 'ann', 'age': 25},]
superplayers = [user for user in users if 'play_time' in user]
print(superplayers)
# resource: https://blog.finxter.com/how-to-filter-a-list-of-dictionaries-in-python/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment