I am working on a discord.py bot and when I am trying to sort the balance of each user for a "top balance" command, it stops sorting correctly if keys have 3 digit numbers.
# bot and discord are defined above here, btw
@bot.command(name='top')
async def top(context):
scores.read("brewscores.ini")
tops = scores['scores']
print('hi\n', tops)
print('sotred')
from collections import Counter #todo : move this somewhere else
c = Counter(tops)
a = c.most_common(5) #//https://stackoverflow.com/a/40496562/9654083
string = """"""
await context.send("Loading balancers...")
for item in a:
print(item)
g, s = item
string += (f"{g}: {s}\n")
em = discord.Embed(title="Top 5 Balancers", description=f'The top 5 contestants are!:{string}')
await context.send(embed=em)
The scores:
[scores]
placeholder = 0
(username censored for privacy) = 35
(username censored for privacy) = 49
No other balancers! = 0
You can stop reading now... = 0
rats#3234 = 100
Output both me and the owner get in Discord when running the command:
(censored for privacy): 49
(censored for privacy): 35
rats#3234: 100
placeholder: 0
you can stop reading now...: 0
The one we expect:
rats#3234: 100
(censored for privacy): 49
(censored for privacy): 35
placeholder: 0
you can stop reading now...: 0
Notice how "rats#3234" was misplaced. We did not see this behaviour in 2- or 1-digit numbers like 99 or 3. Why does this occur?