Vertical Histogram

Question

Given a sentence, write a program that prints the vertical histogram of frequency of words in the sentence.

Solution

stmt = raw_input()
words = stmt.split()
max_length = len(max(words, key=len)) # length of longest word
for cursor in range(max_length):
    for word in words:
        # max_length - cursor is position count
        if (max_length - cursor) <= len(word):
            print '*',
        else:
            print ' ',
    print
Run this
Comments by Disqus