I'm trying to write a function that takes 2 list variables i.e. first_names
and last_names
.
I'm using a nested for loop in my function to iterate through both lists and append the values to return a new 'combined' variable list.
The function takes the two list parameters but iterates through just the first index value [0] of each list and outputs that - the loop ends.
first_names = ["Dave", "James", "Steve"]
last_names = ["Smith", "Jones", "Jackson"]
def NameCombine(first_names,last_names):
combined = []
for first in first_names:
for last in last_names:
combined.append(first+last)
return combined
print(NameCombine(first_names,last_names))
Expected output: DaveSmith, JamesJones, SteveJackson
Actual output: DaveSmith
I'm expecting a new combined list of both the first and last name at each index.
But it's returning the first two values of each list and then the loop ends.