from collections import Counter from typing import List def normalize( n: int, max_ : int ) -> int: return round( ( n / max_ ) * 25 ) def histogram( bins: List[ int ] ) -> str: count = Counter( bins ) m = max( count.values() ) for b in count: count[ b ] = normalize( count[ b ], m ) i = 1 height = 25 s = "" while height > 0: i = 0 for j in sorted( count.keys() ): while i < j: i += 1 s += ' ' if i == j and count[j] >= height: s += '*' else: s += ' ' i += 1 s += '\n' height -= 1 return s import run_tests