I've gone through the Convert all strings in a list to int post
I want to convert
results = ['1', '2', '3']
to:
results = [1, 2, 3]
I know i can do it by
- map(int, results)
and
- results = list(map(int, results))
I want it faster way may be using numpy or more faster.
Actual code is
from sys import stdin, stdout
import numpy as np
n = int(stdin.readline())
for i in range(0,n):
lone = 0
m = int(stdin.readline())
results = stdin.readline().split()
o = np.array(results, dtype=np.int64)
for j in range (0,m):
if o[j] in o[j+1:m]:
lone = lone +1
elif o[j] in o [0:j]:
lone = lone +1
else:
stdout.write(str(o[j]) + '\n')
if lone == m:
stdout.write ("-1 \n")
Please let me know if there is any methods to achieve this when trying to work with thousands of strings