Stem-and-leaf plot: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Added a more general (and declarative) variant, written in terms of groupby and reduce) |
m (→{{header|Python}}: (ljust -> rjust) for stem column) |
||
Line 2,773: | Line 2,773: | ||
def stemLeaf(f, g, s): |
def stemLeaf(f, g, s): |
||
return '\n'.join(map( |
return '\n'.join(map( |
||
lambda x: str(x[0]). |
lambda x: str(x[0]).rjust(2) + ' | ' + |
||
reduce(lambda a, tpl: a + tpl[1] + ' ', x[1], ''), |
reduce(lambda a, tpl: a + tpl[1] + ' ', x[1], ''), |
||
(groupby(sorted( |
(groupby(sorted( |
||
Line 2,803: | Line 2,803: | ||
main()</lang> |
main()</lang> |
||
<pre> |
<pre> 0 | 7 7 |
||
1 |
1 | 2 3 8 8 |
||
2 |
2 | 3 5 7 7 7 7 7 7 8 8 9 9 |
||
3 |
3 | 0 1 1 1 1 2 3 4 5 6 7 7 7 8 9 |
||
4 |
4 | 0 0 1 2 2 2 2 3 3 3 4 4 4 5 6 7 8 8 |
||
5 |
5 | 2 3 7 8 8 |
||
6 |
6 | 1 3 8 |
||
7 |
7 | 1 |
||
9 |
9 | 6 9 |
||
10 | 4 5 5 5 5 6 7 9 9 9 |
10 | 4 5 5 5 5 6 7 9 9 9 |
||
11 | 1 3 3 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 9 9 |
11 | 1 3 3 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 9 9 |