2 for loop same time in python code example
Example 1: python two while loops at same time
import threading
import time
def infiniteloop1():
while True:
print('Loop 1')
time.sleep(1)
def infiniteloop2():
while True:
print('Loop 2')
time.sleep(1)
thread1 = threading.Thread(target=infiniteloop1)
thread1.start()
thread2 = threading.Thread(target=infiniteloop2)
thread2.start()
Example 2: python 2 loops at the same time
import threading
def Task_One():
while True:
print('Rawr')
def Task_Two():
while True:
print('de.cxl ig <3')
threading.Thread(target=Task_One).start()
threading.Thread(target=Task_Two).start()
Example 3: python for loop 2 items at a time
mylist = [117, 202, 287, 372, 457, 542]
point = 490
for i, j in zip(mylist[::2], mylist[1::2]):
if i < point < j:
print ("This point exists between: ", i, " - ", j)
break