Created
May 22, 2019 15:42
-
-
Save Cerebro92/0d3631bf205b206d88cd08f108068601 to your computer and use it in GitHub Desktop.
List Permutations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
final = [] | |
def main(Arr, res): | |
if not Arr: | |
final.append(res) | |
return | |
for elem in Arr: | |
A = copy.deepcopy(Arr) | |
if res is None: | |
local_res = [elem] | |
else: | |
local_res = copy.deepcopy(res) | |
local_res.append(elem) | |
A.remove(elem) | |
main(A, local_res) | |
if __name__ == '__main__': | |
main([1, 2, 3, 4], None) | |
print final | |
print len(final) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with python 2.7
-- python permutation.py