A list has a mixture of full names and their short names. I want to expand the short names to their full name in a list like below. Eg. Pollard should be changed to Kieron Pollard and Starc should be changed to Mitchell Starc.
players = ['Pollard', 'Kieron Pollard', 'Mitchell Starc', 'Pollard', 'Starc']
print(players)
for i, s in enumerate(players):
for p in players:
if len(p) > len(s) and s in p: # Different string
players[i] = p
print(players)
Output:
['Pollard', 'Kieron Pollard', 'Mitchell Starc', 'Pollard', 'Starc']
['Kieron Pollard', 'Kieron Pollard', 'Mitchell Starc', 'Kieron Pollard', 'Mitchell Starc']
The above method works great. I want to know if there is a better and a efficient way of doing the same.