Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

zip lists

# zip lists
names = ['tim', 'bill','joe']
ages = [12,13,15]
fav_color = ['blue','yellow','red']

print(list(zip(names,ages,fav_color)))
Comment

zipping lists

"""
Joining any number of iterables by combining elements in order
    - Iterables include: str, list, tuples, dict etc...
    - No error will be incurred if you zip lists of differing lengths,... 
      ...it will simply zip up to the length of the shortest list
"""
lst1 = [1, 2, 3, 4, 5, 7]
lst2 = "mangos"
lst3 = (3.1, 5.4, 0.2, 23.2, 8.88, 898)
lst4 = {"Car": "Mercedes Benz", "Location": "Eiffel Tower", "Organism": "Tardigrade"}
# lst5, lst6, ...

result = list(zip(lst1, lst2, lst3, lst4.keys())) # Check out dictionary methods

print(result)
## [(1, 'm', 3.1, 'Car'), (2, 'a', 5.4, 'Location'), (3, 'n', 0.2, 'Organism')]
Comment

PREVIOUS NEXT
Code Example
Python :: Pandas Columns Calling 
Python :: pip config proxy 
Python :: creating numpy array using empty 
Python :: print to screen 
Python :: tkinter add text to canvas 
Python :: views django 
Python :: scikit learn library in python 
Python :: run julia in p;ython 
Python :: python if not null 
Python :: vigenere cipher with all printable characters python 
Python :: mathplolib avec date 
Python :: tkinter how to update optionmenu contents 
Python :: how to convert a string to a list python 
Python :: python remove item from list 
Python :: Reading Custom Delimited file in python 
Python :: django-admin startproject 
Python :: python puissance 
Python :: py var to the power of 
Python :: Example code of while loop in python 
Python :: Flatten List in Python Using NumPy concatenate 
Python :: Pillow opencv convert RGB to BRG or RGB to BRG 
Python :: Python Sort Lists 
Python :: django collectstatic with auto yes 
Python :: Forbidden (CSRF token missing or incorrect.): /extension/stripe-pay/ WARNING 2021-06-01 13:45:22,532 log 408 140165573588736 Forbidden (CSRF token missing or incorrect.): /extension/stripe-pay/ 
Python :: flask tutorial 
Python :: matplotlib boxplot change size of outliers 
Python :: tokyo timezone python 
Python :: class python __call__ 
Python :: python manually trigger exception 
Python :: python iterate over tuple of lists 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =