Below Python code is not working. Please explain if anyone can

from sys import stdin, stdout
n, k = map(int, stdin.readline().strip().split())
open_dict = dict()
open_tweets = 0
for i in range(k):
    y = stdin.readline().strip()
    # print(y)
    if y=="CLOSEALL":
        open_tweets = 0
        for j in open_dict:
            open_dict[j] = 0 
    else:
        num = int(y[-1])
        if num in open_dict:
            if open_dict[num]==1:
                open_dict[num]=0 
                open_tweets-=1 
            else:
                open_tweets+=1 
                open_dict[num] = 1 
        else:
            open_tweets+=1 
            open_dict[num] = 1 
    stdout.write(f"{open_tweets}\n")
    
    
    

If I do num = int(y.split()[1]) the code is getting accepted.
ProblemPROBLEM LINK

Consider the test input:

100 2
CLICK 1
CLICK 11

Edit:

Thought this seemed familiar: or this one :stuck_out_tongue: TWTCLOSE - Editorial - #55 by ssjgz

1 Like

:joy:I’m laughing at this error. I submitted 15 times and did’t realise what the error was then I saw someone else’s code and saw that split() was used, still coudn’t realise what the error was :joy:. Thanks man! :fist_left:

1 Like

:fist_right:

2 Likes