map int input split for in range append print print for in range appen

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
N, K = map(int,input().split())
A = []
B = []
for i in range(N):
B.append([])
print(B)
print()
for i in range(K):
A.append(list(input().split()))
if A[i][0] == '+':
print(B[int(A[i][1])-1])
B[int(A[i][1])-1].append(int(A[i][1]))
B[int(A[i][1])-1].append(int(A[i][2]))
B[int(A[i][2])-1].append(int(A[i][1]))
B[int(A[i][2])-1].append(int(A[i][2]))
elif A[0] == '-':
B[int(A[i][1])-1].append(int(A[i][1]))
B[int(A[i][2])-1].append(int(A[i][2]))
else:
if B[int(A[i][1])-1].count(int(A[i][1])) == B[int(A[i][1])-1].count(int(A[i][2])) or B[int(A[i][2])-1].count(int(A[i][1])) == B[int(A[i][2])-1].count(int(A[i][2])):
print('+')
elif B.count(int(A[i][1]))==0 or B.count(int(A[i][2]))== 0:
print(B.count(int(A[i][2])))
print('?')
else:
print('-')
print(A)
print(*B)
print()