Suppose I have an input which contains space seperated integers which are unique, i.e one does not occur twice. In such a case, will using the following,
setA = set(input().split())
be faster than using the below one? If so(I actually experienced it in this way), why?
listA = list(input().split())
Please do not focus on the fact that there is not a conversion to int, while reading the input.
In a problem I am working on, using list() gives timeout, however by using set(), I am able to run it such that it is in the time limitations. I wonder why this is the case?
edit : In case it might be related, the code which is related,
arr = input().split()
for ele in arr:
if ele in setA:
happiness += 1
elif ele in setB:
happiness += -1
else:
pass
Where arr
is a space seperated line of integers, no uniquneness this time.