Created
November 16, 2011 01:06
-
-
Save quandyfactory/1368953 to your computer and use it in GitHub Desktop.
My Python port of Zack Holman's spark shell script: https://github.com/holman/spark
This file contains 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
# -*- coding: utf-8 -*- | |
"""My Python port of Zack Holman's spark shell script: https://github.com/holman/spark | |
This: | |
you@computer:~$ python spark.py 100 20 80 40 60 | |
Should return this: | |
▇▁▅▂▃ | |
""" | |
import sys | |
bars = u'▁▂▃▅▇' | |
def spark(vals): | |
"""Takes a list of values and displays them as a spark""" | |
values = [float(v) for v in vals] | |
low, span = min(values), max(values) - min(values) | |
return u''.join([bars[int(round((val-low)/span*(len(bars)-1), 0))] for val in values]) | |
if __name__ == '__main__': | |
vals = sys.argv[1:] | |
if len(vals) > 0: | |
print spark(vals) | |
else: | |
print "No values entered." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment