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

32 lines
610 B
Python
Raw Normal View History

2019-02-20 12:58:39 +00:00
#!/usr/bin/env python3
2019-03-05 12:23:46 +00:00
# vim: set sw=4 ts=4 et tw=80:
2019-02-20 12:58:39 +00:00
import sys
def histogram(data):
2019-03-05 12:23:46 +00:00
top = max(max(data), 0)
bottom = min(min(data), 0)
i = top
2019-02-20 12:58:39 +00:00
2019-03-05 12:23:46 +00:00
while i >= bottom:
2019-02-20 12:58:39 +00:00
to_print = ""
2019-03-05 12:23:46 +00:00
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)
2019-02-20 12:58:39 +00:00
2019-03-05 12:23:46 +00:00
i = i - 1
2019-02-20 12:58:39 +00:00
def main():
args = [int(x) for x in sys.argv[1:]]
histogram(args)
if __name__ == "__main__":
main()