What's wrong in my code (Closing the tweet | TWTCLOSE| PYTHON)

n, k = map(int, input().split())

ans = []

for _ in range(k):
n = input()

if n == 'CLOSEALL':
    ans = []
else:
    if n[-1] not in ans:
        ans.append(n[-1])
    else:
        ans.remove(n[-1])

print(len(ans))

link to problem: TWTCLOSE Problem - CodeChef

n[-1] is just the last character of n, it’s not the value of X if X is greater than 9

2 Likes

Thanks