I'm trying to create a vertical histogram using only built-in modules. I understand the current histogram function isn't truly a histogram (and the code is probably very ugly), but I'm totally lost on how to create a vertical histogram.
import itertools
def histogram(s):
print("Histogram:")
print("%s %7s %12s" % ( "No.", "Value", "Histogram" ))
for num, count in (s):
print("%3d %7d %s" % (num, count, "*" * count))
text = "Sample text for this example."
word_list = []
word_seq = []
text = text.strip()
for punc in ".,;:!?'-&[]()" + '"' + '/':
text = text.replace(punc, "")
words = text.lower().split()
for word in words:
word_count = len(word)
word_list.append(word_count)
word_list.sort()
for key, iter in itertools.groupby(word_list):
word_seq.append((key, len(list(iter))))
histogram(word_seq)
Any help is greatly appreciated.