Skip to content

Instantly share code, notes, and snippets.

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 eder-projetos-dev/aa8a568d1e1321cd42616ae64d718925 to your computer and use it in GitHub Desktop.
Save eder-projetos-dev/aa8a568d1e1321cd42616ae64d718925 to your computer and use it in GitHub Desktop.
Python - Dictionary Comprehensions
names = ['Alice', 'Bob', 'Charlie']
ages = [25, 32, 40]
people = {name: age for name, age in zip(names, ages)}
@eder-projetos-dev
Copy link
Author

Dictionary Comprehensions

I particularly like dictionary comprehensions when I need to create dictionaries based on existing data. It provides a concise and readable way to build dictionaries with key-value pairs. For example, I can use a dictionary comprehension to create a dictionary mapping names to ages using lists of names and ages.

https://levelup.gitconnected.com/11-tricks-that-will-make-your-life-easier-as-a-python-developer-da29e4306675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment