Middle three digits: Difference between revisions

m
→‎{{header|Python}}: (simplified an expression – max num string length)
m (→‎{{header|Python}}: (simplified an expression – max num string length))
Line 4,033:
-100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0
]
mx = lenmax(maximumBymap(compose(len)(str), xs))
list(map(str, xs))
))
print (
'\n'.join([
Line 4,048 ⟶ 4,046:
 
# GENERIC -------------------------------------------------
 
 
# maximumBycompose (<<<) :: (ab -> ac) -> (a -> b) -> [a] -> ac
def maximumBycompose(fg):
return lambda xsf: reduce(go,lambda xs[1x:], xs[0]g(f(x))
 
 
Line 4,072 ⟶ 4,075:
def Left(x):
return {'type': 'Either', 'Right': None, 'Left': x}
 
 
# maximumBy :: (a -> a -> a) -> [a] -> a
def maximumBy(f):
def go(x, y):
return y if f(y) > f(x) else x
return lambda xs: reduce(go, xs[1:], xs[0])
 
 
9,655

edits