looping through two lists python
for f, b in zip(foo, bar):
print(f, b)
looping through two lists python
for f, b in zip(foo, bar):
print(f, b)
python for loop 2 items at a time
# ------------- For loop using 2 items of a list --------------- #
# This code is trying to find if a point belongs between
# the interval of pairing points of a list:
mylist = [117, 202, 287, 372, 457, 542]
point = 490
# 117 < x < 202 ?
# 287 < x < 372 ?
# 457 < x < 542 ?
for i, j in zip(mylist[::2], mylist[1::2]):
if i < point < j:
print ("This point exists between: ", i, " - ", j)
break
iterate through multiple lists python
# Python program to iterate
# over 3 lists using itertools.zip_longest
import itertools
num = [1, 2, 3]
color = ['red', 'while', 'black']
value = [255, 256]
# iterates over 3 lists and till all are exhausted
for (a, b, c) in itertools.zip_longest(num, color, value):
print (a, b, c)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us