I'm attempting to return a True/False output based on whether numbers in a list are square numbers or not.
The list will need to be checked several times and the list can be any positive integer which means the integer can be very large, in fact, too large for the use of other solutions involving math.sqrt() functions which produce an overflow error shown here:
userList = [1*10**1000]
print ([x for x in userList if math.sqrt(x).is_integer()])
>>>Traceback (most recent call last):
print ([x for x in userList if math.sqrt(x).is_integer()])
OverflowError: int too large to convert to float
Here is my* method:
def squares():
for i in userList:
if i in squares: #the list in which all the square numbers are stored
return True
else:
return False
*My current idea is pre-preparing square numbers into a separate list in order to compare them but I am looking for, perhaps, an alternative, faster method as the userList can become very large.
I want to store the returned output in a separate list as so:
out = []
for i in userList:
out.append(squares())
print(out)
>>>[False,True...]
As you can see this will take a long time when dealing with many numbers and that is the reason as to why I require a faster method.