Here is a nice pythonic way to do this
func = lambda x: round(x,2)
b =[[1.234,2.454],[2.352,9.873]]
b = [list(map(func, i)) for i in b]
print(b)
[[1.23, 2.45], [2.35, 9.87]]
This will create a temporary function which will round a single value to 2 decimal places. We call this function func. Now we want to apply this function to each list in a list so we iterate through our outer list and extract each list inside it. Then we use the map function to apply func to every single element inside this list. We then convert our map iteratable object to a list and we have our answer.
Doing things your way
b =[[1.234,2.454],[2.352,9.873]]
def get_round(x):
temp = []
for i in x:
if type(i) ==list:
x = []
for each_i in i:
x.append(round(each_i,2))
temp.append(x)
else:
temp.append(round(i,2))
return temp
print(get_round(b))
In your original code you were returning too soon. You find the first number in your list of lists, convert it, then return it. This goes back to where we called the function from.