>>> def treemap(lst):
... for i in range(len(lst)):
... if type(lst[i])==int:
... lst[i]=lst[i]**2
... elif type(lst[i])==list:
... treemap(lst[i])
... return lst
>>> lst = [1, 2, 3, [4, [5, 6], 7]]
>>> print(treemap(lst))
[1, 4, 9, [16, [25, 36], 49]]