```
from itertools import chain, imap
def permute(nums):
return [nums] if len(nums) == 1 else list(chain.from_iterable(imap(
lambda i: map(lambda sub: [nums[i]] + sub,
self.permute(nums[0:i] + nums[i + 1:])),
range(len(nums))
)))
```

chain.from_iterable(imap(...)) is equivalent to flatMap.

the 'lambda' function will produce a sublist those start with the same number, e.g. [[1, ...], [1, ...], [1, ...]]