from typing import Counter


def dict_to_str (d, tab="\t", ntab=0):
    """ Transform a multilevel dict to a tabulated str """
    m = ""

    if isinstance(d, Counter):
        for i, j in d.most_common():
            m += "{}{}: {:,}\n".format(tab*ntab, i, j)

    else:
        for i, j in d.items():
            if isinstance(j, dict):
                j = dict_to_str(j, tab=tab, ntab=ntab+1)
                m += "{}{}\n{}".format(tab*ntab, i, j)
            else:
                m += "{}{}: {}\n".format(tab*ntab, i, j)
    return m