I am writing a helper function for flattening lists where i just remove the extra outer lists surrounding an integer: def rem_list(a): if type(a) != list: print a,"about to retu" retu a else: rem_list(a[0]) a = [] lis2 = [2,4,[[2]],[[[1]]], 5, 6, [7]] for each in lis2: a.append(rem_list(each)) print a
I am getting the output as follows: 2 about to retu 4 about to retu 2 about to retu 1 about to retu 5 about to retu 6 about to retu 7 about to retu [2, 4, None, None, 5, 6, None]
I do not understand this. I am retuing an integer in each iteration to rem_list() but its retuing None when there are outer lists present around the character. I have also included a print statement which checks exactly what I am about to retu and it outputs correctly in the print but still retus None. Plz help.
