Answers for "python zip function"

49

python zip function

>>> numbers = [1, 2, 3]
>>> letters = ['a', 'b', 'c']
>>> zipped = zip(numbers, letters)
>>> zipped  # Holds an iterator object
<zip object at 0x7fa4831153c8>
>>> type(zipped)
<class 'zip'>
>>> list(zipped)
[(1, 'a'), (2, 'b'), (3, 'c')]  #list of tuples  
# zip returns tuples
Posted by: Guest on April-02-2020
2

python zip function

>>> letters = ['a', 'b', 'c']
>>> numbers = [0, 1, 2]
>>> for l, n in zip(letters, numbers):
...     print(f'Letter: {l}')
...     print(f'Number: {n}')
...
Letter: a
Number: 0
Letter: b
Number: 1
Letter: c
Number: 2
Posted by: Guest on October-16-2020
1

zip python

>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y))
>>> x == list(x2) and y == list(y2)
True
Posted by: Guest on April-30-2020
0

python zip function

first_name = ['John', 'James', 'Jennifer']
last_name  = ['Doe', 'Bond', 'Smith']
 
students = zip(first_name, last_name)
 
print(list(students))
 
# Output:
# [('John', 'Doe'), ('James', 'Bond'), ('Jennifer', 'Smith')]
Posted by: Guest on October-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language