fork download
  1. def flatten_list(ls=[]):
  2. flattened_list = []
  3.  
  4. def aux(ls):
  5. for elem in ls:
  6. if not isinstance(elem, list):
  7. print("ADDING NO-LIST ELEMENT...")
  8. flattened_list.append(elem)
  9. else:
  10. print("RECURSION...")
  11. aux(elem)
  12.  
  13. aux(ls)
  14.  
  15. return flattened_list
  16.  
  17.  
  18.  
  19. print(flatten_list([[1,2,3,[4,5]],[6,7,8,9],10]))
Success #stdin #stdout 0.03s 9440KB
stdin
1
2
10
42
11
stdout
RECURSION...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
RECURSION...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
RECURSION...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
ADDING NO-LIST ELEMENT...
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]