Let's say currently i have a list with:
L = [[1,'JAYCE'],[2,'AMIE'],[3,'JACK'],[4,'STEVE'],[5,'JAYCE']]
and i have another list which contains the names sorted in order:
sortedNames = ['AMIE','JACK','JAYCE','JAYCE','STEVE']
The output I want to get is, based on the sorted names list, i want to add the ID back to the names in the sorted order which is based off the sortedNames list.
finalist = [[2,'AMIE'],[3,'JACK'],[1,'JAYCE'],[5,'JAYCE'],[4,'STEVE']]
Note that Jayce appeared twice so even if the first occurrence of Jayce has 5, followed by 1, its totally fine too.
I've been thinking of something like:
L = [[1,'JAYCE'],[2,'AMIE'],[3,'JACK'],[4,'STEVE'],[5,'JAYCE']]
sortedNames = ['AMIE','JACK','JAYCE','JAYCE','STEVE']
finalist = []
for i in sortedNames:
j = 0
if i in L[j][1]:
finalist.append(L[0] + i)
j+=1
print(finalist)
I'm getting an error saying:
TypeError: can only concatenate list (not "str") to list
I'm definitely appending it wrong.