Jam/tools.py
2021-10-16 02:09:53 -04:00

25 lines
550 B
Python

# sign function
def sgn(x):
if x>=0:
return 1
return -1
# check whether a number is an integer (with tolerance)
def isint_nonzero(x):
if abs(x)<1e-11:
return False
return abs(round(x)-x)<1e-11
# find the common substring in a list of strings
def common_substr(strings):
out=""
if len(strings)==0:
return out
for i in range(len(strings[0])):
for j in range(1,len(strings)):
if strings[j][i]!=strings[0][i]:
return out
out+=strings[0][i]
return out