def pformat(thing, formatfunc):
    if isinstance(thing, dict):
        return type(thing)((key, pformat(value)) for key, value in thing.
            items())
if isinstance(thing, collections.Container):
    return type(thing)(pformat(value) for value in thing)
if isinstance(thing, numbers.Number):
    return formatfunc(thing)
return thing

def formatfloat(thing):
    return '%.3g' % float(thing)
x = {'a': [1.05600000001, 2.34581736481, [8.1111111112, 9.999990111111]],
    'b': [3.05600000001, 4.34581736481, [5.1111111112, 6.999990111111]]}
print(pformat(x, formatfloat))
Rounding decimals in nested data structures in Python