This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/histogram.py
2019-03-05 13:23:46 +01:00

31 lines
610 B
Python
Executable file

#!/usr/bin/env python3
# vim: set sw=4 ts=4 et tw=80:
import sys
def histogram(data):
top = max(max(data), 0)
bottom = min(min(data), 0)
i = top
while i >= bottom:
to_print = ""
for elem in data:
if i == 0:
to_print += "-"
elif (i > 0 and elem >= i) or \
(i < 0 and elem <= i):
to_print += "#"
else:
to_print += " "
print(to_print)
i = i - 1
def main():
args = [int(x) for x in sys.argv[1:]]
histogram(args)
if __name__ == "__main__":
main()