Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def flat_list(array):
- temp1, junk = re.subn(r'[\[,\]]', ' ', str(array))
- return [int(item) for item in temp1.split()]
- '''
- 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.
- Tests conducted so far that were successful for this function:
- 1. flat_list([1, 2, 3])
- 2. flat_list([1, [2, 2, 2], 4])
- 3. flat_list([[[2]], [4, [5, 6, [6], 6, 6, 6], 7]])
- 4. flat_list([-1, [1, [-2], 1], -1])
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement