Last active
June 3, 2023 16:59
-
-
Save eder-projetos-dev/f01a9ee2b39abbaadf2e7eb04b70e7b8 to your computer and use it in GitHub Desktop.
Python - Zip function
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
names = ['Alice', 'Bob', 'Charlie'] | |
ages = [25, 32, 40] | |
people = list(zip(names, ages)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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