Hasten is_integer

the commented further improvement should be done too imo, but up to you
This commit is contained in:
Gouvernathor 2023-11-11 20:58:07 +01:00 committed by LoafyLemon
parent 19bfc010c8
commit 0d0c54058d
1 changed files with 8 additions and 7 deletions

View File

@ -130,14 +130,15 @@ init python early:
return obj
def is_integer(s):
def zero(s):
return (len(s) > 1 and s.startswith("0"))
s = str(s)
if s and s[0] in ("-", "+"):
return (not zero(s[1:]) and s[1:].isdigit())
return (not zero(s) and s.isdigit())
if not s:
return False
if s[0] in ("-", "+"):
# calling lstrip("0+-") would be faster but not exactly identical
s = s[1:]
if s.lstrip("0").isdigit():
return True
return False
def timeit(func, loops=10000, args=(), kwargs={}):
start = time.time()