Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fast_permute_unique.py
- def permute_unique(nums):
- perms = [[]]
- for n in nums:
- new_perm = []
- for perm in perms:
- for i in range(len(perm) + 1):
- new_perm.append(perm[:i] + [n] + perm[i:])
- # handle duplication
- if i < len(perm) and perm[i] == n: # skips a few
- break
- perms = new_perm
- return perms
- zzz = permute_unique([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3])
- for z in zzz:
- print(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement