fork download
  1. def shallowfy(lista):
  2. shallow = []
  3. for el in lista:
  4. if (isinstance(el, list)):
  5. shallow_el = shallowfy(el)
  6. for subel in shallow_el:
  7. shallow.append(subel)
  8. else:
  9. shallow.append(el)
  10. return shallow
  11.  
  12. print(shallowfy([1, 2, [[[3, [4], 5, [6, 7, [[8, 9], 10, [11]], 12], 13], 14], 15], 16, [17, [[[18]]], 19], 20]))
  13. print(shallowfy([[1, 2], [3, 4, 5], [], [6, 7]]))
  14.  
Success #stdin #stdout 0.02s 9300KB
stdin
Standard input is empty
stdout
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[1, 2, 3, 4, 5, 6, 7]