Godtone (talk | contribs)
Godtone (talk | contribs)
→My Python 3 code: hopefully fixed padding
Line 632: Line 632:
return str(n)+'/'+str(d)
return str(n)+'/'+str(d)
return '[not interval]'
return '[not interval]'
def pad_striv(what, spaces, center = '/'):
def left_pad(what,width,space=' '):
center_loc = what.find(center)
return (width-len(what))*space + what
lhs = what[:center_loc]
def right_pad(what,width,space=' '):
rhs = what[center_loc+len(center):]
return what + (width-len(what))*space
return ' '*(spaces//2 - len(lhs)) + lhs + center + rhs + ' '*(spaces//2 - len(rhs))
def pad(what,width,centre='/',space=' '):
 
if len(what) >= width:
return what
lspaces = (width+1)//2
rspaces = width - lspaces
c = what.find(centre)
if c != -1: # if centre present in what
c += (len(centre)+1)//2
else:
c = (len(what)+1)//2
lspaces -= c
rspaces -= len(what)-c
if lspaces >= 0 and rspaces >= 0:
return lspaces*space + what + rspaces*space
if rspaces < 0 and lspaces >= 0:
return (lspaces+rspaces)*space + what
if lspaces < 0 and rspaces >= 0:
return what + (lspaces+rspaces)*space
return what
# Converts a prime factorisation into a prettier and potentially
# Converts a prime factorisation into a prettier and potentially
# more readable (simple) string representation. (Not for subgroup-factorisations.)
# more readable (simple) string representation. (Not for subgroup-factorisations.)