I have a list x = [['a', 'b', 'c'], ['d'], ['e', 'f', ['g', ['h', 'i']]]]
I want to do all possible permutations of elements in sublists without going beyond corresponding sublist.
I use this generator:
import numpy as np
def ff(x):
if isinstance(x, list) == True:
res = np.random.choice(x, len(x), replace = False)
return [list(map(ff, res))]
else:
print(x)
But however when i do
ff(x)
I get something like this:
[[[[None]], [[None, None, None]], [[[[None, [[None, None]]]], None, None]]]]
Could you tell me please where i made a mistake? The expected output are variations of something like this:
[['c', 'b', 'a'], ['d'], ['f', 'e', ['g', ['i', 'h']]]]
[['d'], ['a', 'b', 'c'], ['f', 'e', [['h', 'i'], 'g']]]
As you see each element is kept in it's square bracket. I need it for tree leafs permutations.