Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python iterate through lists itertools

import itertools

list_1 = [1, 2, 3, 4]
list_2 = ['a', 'b', 'c']

# loop until the short loop stops
for i,j in zip(list_1,list_2):
    print(i,j)

print("
")

# loop until the longer list stops
for i,j in itertools.zip_longest(list_1,list_2):
    print(i,j)
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #python #iterate #lists #itertools
ADD COMMENT
Topic
Name
7+9 =