The following function replaces an integer from one list with the integer in the next list of the same position IF the second integer is larger... What im having trouble understanding is what the tmp variable does and how the actual swapping takes place inside the for loop...
def swapLowHigh(list1, list2):
for i in range(0, len(list2)):
if i < len(list1) and list1[i] < list2[i]:
tmp = list2[i]
list2[i] = list1[i]
list1[i] = tmp
l1 = [1,9,5,4]
l2 = [2,8,7,3,8,1]
swapLowHigh(l1, l2)
print(l1)
print(l2)
#output
[2, 9, 7, 4]
[1, 8, 5, 3, 8, 1]