“función de zip python” Código de respuesta

Python Zip ()

languages = ['Java', 'Python', 'JavaScript']
versions = [14, 3, 6]

result = zip(languages, versions)
print(list(result))

# Output: [('Java', 14), ('Python', 3), ('JavaScript', 6)]

print(dict(result))

# Output: {'Java': 14, 'Python': 3, 'JavaScript': 6}
Evil Echidna

función de zip python

namelist = ["Avish", "Piyush", "Tom"]
agelist = [17, 22, 38]

for name, age in zip(namelist, agelist):
    print(name, age)

# Avish 17
# Piyush 22
# Tom 38
patrick204nqh

Python Zip

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> c = zip(a, b)
>>> print(c)
<zip object at 0x7f55cfca3080>
>>> list(c)
[(1, 4), (2, 5), (3, 6)]
Filthy Fox

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
Helpless Hare

función de zip python

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')]
Glorious Gnat

Respuestas similares a “función de zip python”

Preguntas similares a “función de zip python”

Más respuestas relacionadas con “función de zip python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código