Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import re
  2. def flat_list(array):
  3. temp1, junk = re.subn(r'[\[,\]]', ' ', str(array))
  4. return [int(item) for item in temp1.split()]
  5.  
  6.  
  7. '''
  8. The function flat_list splits the array input into temp1 and junk such that temp1 contains all the characters other than ']' and '[' that are instead stored in the variable junk.
  9.  
  10. Tests conducted so far that were successful for this function:
  11. 1. flat_list([1, 2, 3])
  12. 2. flat_list([1, [2, 2, 2], 4])
  13. 3. flat_list([[[2]], [4, [5, 6, [6], 6, 6, 6], 7]])
  14. 4. flat_list([-1, [1, [-2], 1], -1])
  15. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement