hats = ["red", "black", "blue", "yellow"] ids = [2, 7, 15, 22, 25, 34] newIds = [] # Initialize a new list so we can add to it in a loop for id in ids: if id % 2 == 0: # is the number even? (is the remainder 0 after division by 2?) newIds.append(id + 1) elif id % 2 == 1: # is the number odd? (remainder == 1 after division by 2?) newIds.append(id - 1) # len(hats) → length of the "hats" list; range(len(hats)) list containing [0, 1, 2, … n], where n is the length of the list minus 1 (the last index of "hats") for i in range(len(hats)): print "person with id", newIds[i], "has a", hats[i], "hat"