-1
def flatten(aList):
    if len(aList) == 1:
        return aList
    else:
        return flatten(aList[:-1])]

I want it to return a flatten list of the original list, pass to the function. After passing it this a list, it only returns the first element.

List = [68, -99,"abc", -8,100, [-92, 89, 81, 96]]
flatten(List)
karel
  • 5,489
  • 46
  • 45
  • 50

1 Answers1

0

Try this

List = [68, -99,"abc", -8,100, [-92, 89, 81, 96]]

result = []
def flatten(my_list):
    for i in my_list:
        if isinstance(i, list):
            return flatten(i)
        else:
            result.append(i)
    return result

print(flatten(List))
danidee
  • 9,298
  • 2
  • 35
  • 55