Print histogram in python 3 -
i have word length_of_word | repetitions dictionary , want make histogram of 1 in link below using python built in functions no numpy or it.
http://dev.collabshot.com/show/723400/
please me out @ least pointers.
i guess must have dict looks one, right ?
>>> d = {1:1, 2:10, 3:10, 4:6, 5:5, 6:4, 7:2, 8:1} >>> d {1: 1, 2: 10, 3: 10, 4: 6, 5: 5, 6: 4, 7: 2, 8: 1} if so, have function trick:
>>> def histo(dict_words): # max values, plus delta ease display x_max = max(dict_words.keys()) + 2 y_max = max(dict_words.values()) + 2 # print line per line print '^' j in range(y_max, 0, -1): s = '|' in range(1, x_max): if in dict_words.keys() , dict_words[i] >= j: s += '***' else: s += ' ' print s # print x axis s = '+' in range(1, x_max): s += '---' s += '>' print s # print indexes s = ' ' in range(1, x_max): s += ' %d ' % print s >>> histo(d) ^ | | | ****** | ****** | ****** | ****** | ********* | ************ | *************** | *************** | ****************** |************************ +---------------------------> 1 2 3 4 5 6 7 8 9 >>> ok, there's little more work display values on left , format correctly numbers greater 10 not have shift in indexes, think it's start :-)
Comments
Post a Comment