How to iterate over the elements of two lists at the same time in Python
Why, you can go with zip()
. Here is a cleaner solution.
people=['Mary','Joe']
genders=['she','he']
for person,gender in zip(people,genders):
print(person)
print("{} is happy".format(gender))
Output:
Mary
she is happy
Joe
he is happy