darkcatsenpai
darkcatsenpai

Reputation: 11

"TypeError: list indices must be integers or slices, not tuple" when trying to compare string

Im currently writing a game for a bot in discord.py, which has a leaderboard. for the leaderboard i am using a nested list with a lenght of 100 (max players), which contains a name and a score ("name", "score") in every index. Whenever i try to use my for loop to check exceptions, the console throws this at me: TypeError: list indices must be integers or slices, not tuple

for i in leaderboard:
    if benutzerstr[x]==leaderboard[i][0]:
      leaderboard[i][1]+=2
    else: 
      if leaderboard[i][0]!="name":
        i+=1
      else:
        leaderboard[i][0]=benutzerstr[x]
        leaderboard[i][1]=2
    i+=1

in my current case, benutzerstr[x] holds the name "darkcat." in it, x has the value 3. It would be nice to get a quick respond, as this problem is pretty much holding me from making any progress with my bot.

Upvotes: 0

Views: 102

Answers (1)

darkcatsenpai
darkcatsenpai

Reputation: 11

This here is my answer, i thought that for i in leaderboard was an index, but it wasn't. Thank you for your help.

for i in range(0, len(leaderboard)):
        if benutzerstr[x] not in leaderboard:
          if benutzerstr[x]==leaderboard[i][0]:
            leaderboard[i][1]+=2
          else: 
            if leaderboard[i][0]!="-":
                i+=1
            else:
              leaderboard[i][0]=benutzerstr[x]
              leaderboard[i][1]=2

Upvotes: 1

Related Questions