playerLevel = ['X', 'Y', 'X', 'Z']
sameLevel = defaultdict(list)
for idx, level in enumerate(playerLevel):
    sameLevel[level].append(idx)
print(list(sameLevel.values()))
How to sort a list by the value of its elements, with the value defined in a different list in Python