Created
March 20, 2017 05:45
-
-
Save clintval/5d4e0043cb04941ebbc7d22281762598 to your computer and use it in GitHub Desktop.
A Python port of spark: https://github.com/holman/spark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def spark(arr): | |
if len(arr) <= 1: | |
return '▅' | |
elif min(arr) == max(arr): | |
return ''.join(['▅' for _ in arr]) | |
ticks = ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█') | |
norm = [round(7 * (x - min(arr)) / (max(arr) - min(arr))) for x in arr] | |
return ''.join([ticks[int(num)] for num in norm]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment