Home>

Basically, I have an array:

All sorts of things are stored in it

I am using del mas [i] But it doesn't work

Here is my code:

with open ('keys.json', 'r', encoding= 'utf-8') as f: # opened the data file
            mas= json.load (f) # drove everything that received
    print (key)
    for i in range (len (mas)):
        if (mas [i]== key):
            print (mas)
            await bot.send_message (
                    chat_id= message.chat.id,
                    text= "okay"
                    )
            text= 1
            sql.execute (f'UPDATE users SET sub= {text} WHERE user_id= {message.from_user.id} ')
            int (i)
            del mas [i]
        else:
            await bot.send_message (
                    chat_id= message.chat.id,
                    text= "not okay")

key is the data entered by the user

And here is the error (IndexError: list index out of range)

it is better to attach text information in the form of text: a) it is easier to read; b) can be copied; c) the search works. you can correct the text of the question by clicking edit below the text of the question

aleksandr barakin2021-11-27 00:51:11

There is no JSON array. JSON is a string. Once you've converted it to a python object /array /list, etc. forget about the word JSON.

Alexey Ten2021-11-27 00:51:11