Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python zip print two list

for i,j in zip(a,b):
	print (i, j)
Comment

zip multiple lists

# zip multiple lists
names = [ ' tim ', ' joe ' , ' billy ', ' sally ' ]
ages = [ 21, 19, 18, 43 ]
eye_color = [ ' blue ' , ' brown ' , ' brown ' , ' green ']
print(list(zip(names, ages, eye_color)))  		# return list of tuples  [ ( ' tim ', 21 , ' blue ' ), ( ' joe ' , 19 , ' brown '), ( ' billy ', 18, ' brown ' ), ( ' sally ', 43 , ' green ' )]

for name, age in zip( names, ages ) :
	if age > 20 :
		print(name)				# tim sally
Comment

zip 2 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

zip() in Python: Get elements from multiple lists

d = {'k1': 1, 'k2': 2}

# d.update(k3=3, k3=300)
# SyntaxError: keyword argument repeated: k3

d = {'k1': 1, 'k2': 2}

d.update([('k3', 3), ('k3', 300)])
print(d)
# {'k1': 1, 'k2': 2, 'k3': 300}

d = {'k1': 1, 'k2': 2}

keys = ['k3', 'k3']
values = [3, 300]

d.update(zip(keys, values))
print(d)
# {'k1': 1, 'k2': 2, 'k3': 300}
Comment

PREVIOUS NEXT
Code Example
Python :: how to get any letter of a string python 
Python :: python pandas table save 
Python :: root.iconbitmap 
Python :: bulk create django 
Python :: df empty python 
Python :: planets python 
Python :: how to print a variable in python 
Python :: python if string contains substring 
Python :: django url patterns static 
Python :: pygame mixer documentation 
Python :: python code for string title 
Python :: python convert to hmac sha256 
Python :: df to sql mysql 
Python :: entropy formula pyhon 
Python :: python uppercase 
Python :: if string is in array python 
Python :: python script in excel 
Python :: Python of add two numbers 
Python :: how to use .format in python 
Python :: remove leading and lagging spaces dataframe python 
Python :: combine df columns python 
Python :: remove rows from pandas 
Python :: 405 status code django 
Python :: torch.stack example 
Python :: numpy get diagonal matrix from matrix 
Python :: python max function with lambda 
Python :: async python 
Python :: parentheses in python 
Python :: install python3 in ubuntu 
Python :: make a condition statement on column pandas 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =