Sparkline in unicode: Difference between revisions
m
→{{header|Python}}
(→{{header|Python}}: Tidied, updated primitives.) |
|||
Line 1,871:
from functools import reduce
import operator
import re
# ------------------- LABELLED SPARKLINE -------------------
# sparkLine :: [Float] -> [String]
def sparkLine(xs):
'''Unicode sparkline summary of a
Line 1,889:
w = (mx - mn) / 8
lbounds = list(map(lambda i: mn + (w * i), range(1, 8)))
le = curry(operator.le)
# spark :: Float -> Char
def spark(x):
def go(i):
return '▁▂▃▄▅▆▇'[i]
return maybe('█')(go)(
findIndex(
)
return [
Line 1,960 ⟶ 1,962:
return fg
return reduce(go, fs, lambda x: x)
# curry :: ((a, b) -> c) -> a -> b -> c
def curry(f):
'''A curried function derived
from an uncurried function.
'''
return lambda x: lambda y: f(x, y)
Line 2,025 ⟶ 2,035:
# MAIN ---
if __name__ == '__main__':
main()</lang>
|