I have the two following nested lists
List 1: [["Bob", "Davon", "Alex"],["Dylan","Rose", "Hard"]]
List 2: [["Red", "Black"] , ["Blue", "Green"], ["Yellow", "Pink"]]
And want to show the first word of each list within the nest together, the second etc. So that the outcome would be:
['Bob and Dylan', 'Davon and Rose', 'Alex and Hard'] --> for the first list
['Red and Blue and Yellow, 'Black and Green and Pink'] --> for the second list
So the first outcome I can get with the following code
name_list = [["Bob", "Davon", "Alex"],["Dylan","Rose", "Hard"]]
def addition(name_list):
new_list = []
for i in range(len(name_list)):
for j in range(len(name_list[i])):
new_list.append(name_list[i][j] + " and " + name_list[i+1][j])
return new_list
addition (name_list)
But the second list: [["Red", "Black"] , ["Blue", "Green"], ["Yellow", "Pink"]] does not provide the right outcome.
zip(*my_list)transposes your lists of lists into new versions which are then easy to manipulate into the detailed strings you want.