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/f01a9ee2b39abbaadf2e7eb04b70e7b8 to your computer and use it in GitHub Desktop.
Save eder-projetos-dev/f01a9ee2b39abbaadf2e7eb04b70e7b8 to your computer and use it in GitHub Desktop.
Python - Zip function
names = ['Alice', 'Bob', 'Charlie']
ages = [25, 32, 40]
people = list(zip(names, ages))
@eder-projetos-dev
Copy link
Author

Using the zip() function:

I find the zip() function quite useful when I need to combine two lists into a list of tuples. For example, if I have separate lists of names and ages, I can use zip() to pair each name with its corresponding age. This allows me to work with related data as a cohesive unit.

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