19.1 Problem

In statistics a useful technique used to visualize the distribution of data is histogram. A bit less popular, although easier to implement with text display is stem and leaf plot.

So here is a task for you:

As a minimal test, make sure it works correctly on the examples from the Wikipedia’s web page, i.e.

# prime numbers below 100
stemLeafTest1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
                41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
# example from the Construction section
stemLeafTest2 = [44, 46, 47, 49, 63, 64, 66, 68, 68, 72, 72, 75,
                76, 81, 84, 88, 106]
# another example from the Construction section
stemLeafTest3 = [-23.678758, -12.45, -3.4, 4.43, 5.5, 5.678,
                16.87, 24.7, 56.8]

Notice that if you broaden the range of input numbers (e.g. by appending 300 or 400, to stemLeafTest1) you will still get a printout, but the plot won’t be so pretty.



CC BY-NC-SA 4.0 Bartlomiej Lukaszuk