Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def flatten(li):
- flat_li = []
- for e in li:
- if isinstance(e, list):
- flat_li += flatten(e)
- else:
- flat_li.append(e)
- return flat_li
- def ndeep(folder, n):
- files = []
- if n == 0:
- return folder
- for file in folder:
- if isinstance(file, list):
- files += ndeep(file, n-1)
- return flatten(files)
- # folder = ['a', ['b'], ['c', [['d'], 'e']]]
- # n = 3
- # print(ndeep(folder, n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement