Lets say I have a game where the players are denoted by a unique number. Then, say I have a list with a bunch of randomly chosen players, called playerList. So, the list isn't ordered(this could represent a bunch of players signing up for some contest, for example). Then, I have a second list called playerLevel, where the i'th entry tells you the level the i'th player is on.
So, if playerLevel = ['X', 'Y', 'X', 'Z'], then players 1 and 3 are on level X, player 2 is on level Y, and player 4 is on level Z.
Using list comprehensions, how can I make a new list(lets call it samelevel) where the player numbers are sorted into sublists, based on the players being on the same level?
So, in this example, sameLevel = [[1,3],[2],[4]]
I'd like to do this in a way that looks elegant. Ideally, using a main loop that looks like "for element in playerLevel:" and so on. How can I do this? Thanks!