def treemap(lst): cp = list() for element in lst: if isinstance(element, list): cp.append(treemap(element)) else: cp.append(element**2) return cp