def moreCanonicalStr(var):
    """Return a string representation of var, similar to the one obtained by
    str, only when iterating through dictionaries, go by key order.
    """
    if isinstance(var, dict):
        ret = "{"
        keys = var.keys()
        sortedKeys = sorted(keys)
        for k in sortedKeys:
            ret += str(k) + ": " + moreCanonicalStr(var[k]) + ", "
        ret = ret[:-2] + "}"
    else:
        ret = str(var)

    return ret