Skip to content

Sort players by rank

The utils modules provides a function which takes a list of players and returns a new list of the same players, but sorted

# Get players
riot_ids = [
    "bexli#bex",
    "mltsimpleton#na1",
    "roninalex#na1",
    "poydok#na1",
    "boxrog#na1",
    "vynle#na1",
]

print(f"Fetching {len(riot_ids)} players...\n")

# Fetch all players in parallel
players = await client.get_players(riot_ids)

# Players sorted by rank
sorted_players = await sort_players_by_rank(players)

# Print them!
for player in sorted_players:
    solo_rank = await player.get_solo_rank()
    rank_text = (
        f"{solo_rank.tier} {solo_rank.division:<3} ({solo_rank.league_points} LP)"
        if solo_rank  # Handle unranked
        else "Unranked!"
    )
    print(f"{player.game_name:<12} :: {rank_text}")