def sorted_tree(ls):
    """
    Recursively sort a nested list to get a canonical version.
    """
    if ls is None: return ls
    for i in range(len(ls)):
        if type(ls[i]) is list:
            ls[i] = sorted_tree(ls[i])
    ls.sort()
    return ls