From 128020b6e53873b72d373eb83e275d8d2f126f74 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:34:45 +0530 Subject: [PATCH 01/24] Add files via upload --- .../__pycache__/permutations.cpython-310.pyc | Bin 0 -> 863 bytes data_structures/Arrays/permutations.py | 31 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 data_structures/Arrays/__pycache__/permutations.cpython-310.pyc create mode 100644 data_structures/Arrays/permutations.py diff --git a/data_structures/Arrays/__pycache__/permutations.cpython-310.pyc b/data_structures/Arrays/__pycache__/permutations.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7d1c255c026d84f88be7086bc981c9b23dd94c20 GIT binary patch literal 863 zcmchVL2uJA6vzEyCoNrD217`@z{IT=a)bjy40hgSLZC?qMYSo}S|@vUDk{0sq;cX? zw8woVUpeh7aN@m`p(4Q*NADNg@1Gav|56PGJwfArcsI_a5Z`&RJu+InqHqi?j4-e- zG|;`B?Tb%JCt7}0r^!FEN~e^SIy(`gPE@v;xtO8x4cakK(c8gqN-5q@xHG~;EWwK) zu0X?if`cGduoe?I5kA@MU%`?1@OYU}M(Sh@OX(HsmntaAbe3sIS80%I0C8~;V3h^M zbJE}L?ggrMEst;bC^r;*NI5k&s&Q2>Vv2>Gm?-P2j-A@ztnnshMO_=KV`jd1x{osC zr}?W~GxZV52sZXN>cW?mby4x^THt*W{&=3hbp~BtSoax=GeS8poG<1@eq`Lauj>2| zu~@i#yT;Rcf!wTw!aXD?=tB>7DY|s=yblUm%^%KoNc-E_Z?yP7&eB`5z#ZD54kaO* z1HKL!IZvIUemo2GM list[list[int]]: + result=[] + if len(nums)==1: + return [nums.copy()] + for i in range(len(nums)): + n=nums.pop(0) + permutations=permute(nums) + for perm in permutations: + perm.append(n) + result.extend(permutations) + nums.append(n) + return result + +# Unique permutations: +def permute_unique(nums: list[int]) -> list[list[int]]: + result=[] + if len(nums)==1: + return [nums.copy()] + for i in range(len(nums)): + n=nums.pop(0) + permutations=permute_unique(nums) + for perm in permutations: + perm.append(n) + result.extend(permutations) + nums.append(n) + ans=[] + for i in result: + if i not in ans: + ans.append(i) + return ans \ No newline at end of file From 0fe013e3f9020ff6671025b0e47f9308f8ac845a Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:36:57 +0530 Subject: [PATCH 02/24] Delete permutations.cpython-310.pyc --- .../__pycache__/permutations.cpython-310.pyc | Bin 863 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 data_structures/Arrays/__pycache__/permutations.cpython-310.pyc diff --git a/data_structures/Arrays/__pycache__/permutations.cpython-310.pyc b/data_structures/Arrays/__pycache__/permutations.cpython-310.pyc deleted file mode 100644 index 7d1c255c026d84f88be7086bc981c9b23dd94c20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 863 zcmchVL2uJA6vzEyCoNrD217`@z{IT=a)bjy40hgSLZC?qMYSo}S|@vUDk{0sq;cX? zw8woVUpeh7aN@m`p(4Q*NADNg@1Gav|56PGJwfArcsI_a5Z`&RJu+InqHqi?j4-e- zG|;`B?Tb%JCt7}0r^!FEN~e^SIy(`gPE@v;xtO8x4cakK(c8gqN-5q@xHG~;EWwK) zu0X?if`cGduoe?I5kA@MU%`?1@OYU}M(Sh@OX(HsmntaAbe3sIS80%I0C8~;V3h^M zbJE}L?ggrMEst;bC^r;*NI5k&s&Q2>Vv2>Gm?-P2j-A@ztnnshMO_=KV`jd1x{osC zr}?W~GxZV52sZXN>cW?mby4x^THt*W{&=3hbp~BtSoax=GeS8poG<1@eq`Lauj>2| zu~@i#yT;Rcf!wTw!aXD?=tB>7DY|s=yblUm%^%KoNc-E_Z?yP7&eB`5z#ZD54kaO* z1HKL!IZvIUemo2GM Date: Tue, 25 Oct 2022 06:09:17 +0000 Subject: [PATCH 03/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/Arrays/permutations.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/data_structures/Arrays/permutations.py b/data_structures/Arrays/permutations.py index d293b07ae03a..175c474080db 100644 --- a/data_structures/Arrays/permutations.py +++ b/data_structures/Arrays/permutations.py @@ -1,31 +1,32 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for i in range(len(nums)): - n=nums.pop(0) - permutations=permute(nums) + n = nums.pop(0) + permutations = permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) return result + # Unique permutations: def permute_unique(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for i in range(len(nums)): - n=nums.pop(0) - permutations=permute_unique(nums) + n = nums.pop(0) + permutations = permute_unique(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) - ans=[] + ans = [] for i in result: if i not in ans: ans.append(i) - return ans \ No newline at end of file + return ans From 3f5d5cb1d4829706582153b99f727137e53c7f86 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:41:58 +0530 Subject: [PATCH 04/24] Update permutations.py --- data_structures/Arrays/permutations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/Arrays/permutations.py b/data_structures/Arrays/permutations.py index 175c474080db..ff9f1060263f 100644 --- a/data_structures/Arrays/permutations.py +++ b/data_structures/Arrays/permutations.py @@ -18,7 +18,7 @@ def permute_unique(nums: list[int]) -> list[list[int]]: result = [] if len(nums) == 1: return [nums.copy()] - for i in range(len(nums)): + for _ in range(len(nums)): n = nums.pop(0) permutations = permute_unique(nums) for perm in permutations: From 9258074138ddca2d9d743b521d59bf4680cebd19 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:43:24 +0530 Subject: [PATCH 05/24] Update permutations.py --- data_structures/Arrays/permutations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/Arrays/permutations.py b/data_structures/Arrays/permutations.py index ff9f1060263f..1d9e19ee3479 100644 --- a/data_structures/Arrays/permutations.py +++ b/data_structures/Arrays/permutations.py @@ -3,7 +3,7 @@ def permute(nums: list[int]) -> list[list[int]]: result = [] if len(nums) == 1: return [nums.copy()] - for i in range(len(nums)): + for _ in range(len(nums)): n = nums.pop(0) permutations = permute(nums) for perm in permutations: From 09e81478dfa2ab5c57567bf7b3249ddfe52fe568 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:46:16 +0530 Subject: [PATCH 06/24] Add files via upload --- data_structures/arrays/permutations.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 data_structures/arrays/permutations.py diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py new file mode 100644 index 000000000000..35fc61b6376b --- /dev/null +++ b/data_structures/arrays/permutations.py @@ -0,0 +1,31 @@ +# All permutations: +def permute(nums: list[int]) -> list[list[int]]: + result=[] + if len(nums)==1: + return [nums.copy()] + for _ in range(len(nums)): + n=nums.pop(0) + permutations=permute(nums) + for perm in permutations: + perm.append(n) + result.extend(permutations) + nums.append(n) + return result + +# Unique permutations: +def permute_unique(nums: list[int]) -> list[list[int]]: + result=[] + if len(nums)==1: + return [nums.copy()] + for _ in range(len(nums)): + n=nums.pop(0) + permutations=permute_unique(nums) + for perm in permutations: + perm.append(n) + result.extend(permutations) + nums.append(n) + ans=[] + for i in result: + if i not in ans: + ans.append(i) + return ans \ No newline at end of file From f36374babf08288163e402a26f37ed19e3322af4 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:46:32 +0530 Subject: [PATCH 07/24] Delete permutations.py --- data_structures/Arrays/permutations.py | 32 -------------------------- 1 file changed, 32 deletions(-) delete mode 100644 data_structures/Arrays/permutations.py diff --git a/data_structures/Arrays/permutations.py b/data_structures/Arrays/permutations.py deleted file mode 100644 index 1d9e19ee3479..000000000000 --- a/data_structures/Arrays/permutations.py +++ /dev/null @@ -1,32 +0,0 @@ -# All permutations: -def permute(nums: list[int]) -> list[list[int]]: - result = [] - if len(nums) == 1: - return [nums.copy()] - for _ in range(len(nums)): - n = nums.pop(0) - permutations = permute(nums) - for perm in permutations: - perm.append(n) - result.extend(permutations) - nums.append(n) - return result - - -# Unique permutations: -def permute_unique(nums: list[int]) -> list[list[int]]: - result = [] - if len(nums) == 1: - return [nums.copy()] - for _ in range(len(nums)): - n = nums.pop(0) - permutations = permute_unique(nums) - for perm in permutations: - perm.append(n) - result.extend(permutations) - nums.append(n) - ans = [] - for i in result: - if i not in ans: - ans.append(i) - return ans From 3def3fb5f36747b22680591b62ac1fb8dfebf64f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:17:03 +0000 Subject: [PATCH 08/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 35fc61b6376b..1d9e19ee3479 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,31 +1,32 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for _ in range(len(nums)): - n=nums.pop(0) - permutations=permute(nums) + n = nums.pop(0) + permutations = permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) return result + # Unique permutations: def permute_unique(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for _ in range(len(nums)): - n=nums.pop(0) - permutations=permute_unique(nums) + n = nums.pop(0) + permutations = permute_unique(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) - ans=[] + ans = [] for i in result: if i not in ans: ans.append(i) - return ans \ No newline at end of file + return ans From 84a7e46e8a5705275ad16e65fd3358d494037d37 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:00:57 +0530 Subject: [PATCH 09/24] Update permutations.py --- data_structures/arrays/permutations.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 1d9e19ee3479..31f6d4155842 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -13,20 +13,6 @@ def permute(nums: list[int]) -> list[list[int]]: return result -# Unique permutations: -def permute_unique(nums: list[int]) -> list[list[int]]: - result = [] - if len(nums) == 1: - return [nums.copy()] - for _ in range(len(nums)): - n = nums.pop(0) - permutations = permute_unique(nums) - for perm in permutations: - perm.append(n) - result.extend(permutations) - nums.append(n) - ans = [] - for i in result: - if i not in ans: - ans.append(i) - return ans +if __name__=="__main__": + nums=[1,2,3] + print(permute(nums)) From 7cbdfffdfef4c606605c84eccf9d4f58dbebca48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:31:46 +0000 Subject: [PATCH 10/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 31f6d4155842..8a3d4d2e82ff 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -13,6 +13,6 @@ def permute(nums: list[int]) -> list[list[int]]: return result -if __name__=="__main__": - nums=[1,2,3] - print(permute(nums)) +if __name__ == "__main__": + nums = [1, 2, 3] + print(permute(nums)) From 677af801c69b486d2e7394ec2fb77ac4581146e3 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:12:21 +0530 Subject: [PATCH 11/24] Update permutations.py --- data_structures/arrays/permutations.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 8a3d4d2e82ff..79d704617d0a 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,11 +1,11 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result = [] - if len(nums) == 1: + result=[] + if len(nums)==1: return [nums.copy()] for _ in range(len(nums)): - n = nums.pop(0) - permutations = permute(nums) + n=nums.pop(0) + permutations=permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) @@ -13,6 +13,10 @@ def permute(nums: list[int]) -> list[list[int]]: return result -if __name__ == "__main__": - nums = [1, 2, 3] - print(permute(nums)) +def main() -> None: + nums=[1,2,3] + print("permutations are:",permute(nums)) + +if __name__=="__main__": # Main function for testing. + main() + From 1d8ead923fe4708daf79ee95501e9cc88486f845 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:43:35 +0000 Subject: [PATCH 12/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 79d704617d0a..7aba76f3a9e1 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,11 +1,11 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for _ in range(len(nums)): - n=nums.pop(0) - permutations=permute(nums) + n = nums.pop(0) + permutations = permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) @@ -14,9 +14,9 @@ def permute(nums: list[int]) -> list[list[int]]: def main() -> None: - nums=[1,2,3] - print("permutations are:",permute(nums)) + nums = [1, 2, 3] + print("permutations are:", permute(nums)) -if __name__=="__main__": # Main function for testing. - main() - + +if __name__ == "__main__": # Main function for testing. + main() From 53960753ab048191a46757cf8876a04b3b5a8a3b Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:14:55 +0530 Subject: [PATCH 13/24] Update permutations.py --- data_structures/arrays/permutations.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 7aba76f3a9e1..49041619ab77 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,22 +1,20 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result = [] - if len(nums) == 1: + result=[] + if len(nums)==1: return [nums.copy()] for _ in range(len(nums)): - n = nums.pop(0) - permutations = permute(nums) + n=nums.pop(0) + permutations=permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) return result +def main() -> None: # Main function for testing. + nums=[1,2,3] + print("permutations are:",permute(nums)) -def main() -> None: - nums = [1, 2, 3] - print("permutations are:", permute(nums)) - - -if __name__ == "__main__": # Main function for testing. - main() +if __name__=="__main__": + main() From d78301c62c8f851819c32254baf0b8a5a538d773 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:45:42 +0000 Subject: [PATCH 14/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 49041619ab77..b6c03c50b69d 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,20 +1,22 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: - result=[] - if len(nums)==1: + result = [] + if len(nums) == 1: return [nums.copy()] for _ in range(len(nums)): - n=nums.pop(0) - permutations=permute(nums) + n = nums.pop(0) + permutations = permute(nums) for perm in permutations: perm.append(n) result.extend(permutations) nums.append(n) return result -def main() -> None: # Main function for testing. - nums=[1,2,3] - print("permutations are:",permute(nums)) -if __name__=="__main__": - main() +def main() -> None: # Main function for testing. + nums = [1, 2, 3] + print("permutations are:", permute(nums)) + + +if __name__ == "__main__": + main() From 38b690ffef251e9d78f0c7e59f80995ff985582b Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 09:46:16 +0530 Subject: [PATCH 15/24] Update data_structures/arrays/permutations.py Co-authored-by: Christian Clauss --- data_structures/arrays/permutations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index b6c03c50b69d..6aac70917aa1 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,5 +1,11 @@ # All permutations: def permute(nums: list[int]) -> list[list[int]]: + """ + >>> from itertools import permutations + >>> numbers in ([], [1], [1, 2], [2, 1], [-1, -3, -2], [5.5, 3.3, 4.4, 1.1, 2.2]) + >>> all(permute(nums) == permutations(nums) for nums in numbers) + True + """ result = [] if len(nums) == 1: return [nums.copy()] From 3638192d77f6a0f8d15db3477ba8f342f4ca4532 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 10:21:30 +0530 Subject: [PATCH 16/24] Update permutations.py --- data_structures/arrays/permutations.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 6aac70917aa1..1c11449bca27 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -2,8 +2,8 @@ def permute(nums: list[int]) -> list[list[int]]: """ >>> from itertools import permutations - >>> numbers in ([], [1], [1, 2], [2, 1], [-1, -3, -2], [5.5, 3.3, 4.4, 1.1, 2.2]) - >>> all(permute(nums) == permutations(nums) for nums in numbers) + >>> numbers= [1,2,3] + >>> all(list(nums) in permute(numbers) for nums in permutations(numbers)) True """ result = [] @@ -18,10 +18,11 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result - +from itertools import permutations def main() -> None: # Main function for testing. - nums = [1, 2, 3] + numbers = [1, 2, 3] print("permutations are:", permute(nums)) + print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) if __name__ == "__main__": From e73d2cabd9b87f7499c706cbd9f2552f9f694c48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 04:52:52 +0000 Subject: [PATCH 17/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 1c11449bca27..832d6dd69934 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -18,11 +18,17 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result + from itertools import permutations + + def main() -> None: # Main function for testing. numbers = [1, 2, 3] print("permutations are:", permute(nums)) - print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) + print( + "isValid:", + all(list(nums) in permute(numbers) for nums in permutations(numbers)), + ) if __name__ == "__main__": From 6f82262e7b698710a9a3ce05df8254ca9ab71dbb Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 10:26:00 +0530 Subject: [PATCH 18/24] Update permutations.py --- data_structures/arrays/permutations.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 832d6dd69934..753ef3e66245 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,3 +1,4 @@ +from itertools import permutations # All permutations: def permute(nums: list[int]) -> list[list[int]]: """ @@ -18,17 +19,10 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result - -from itertools import permutations - - def main() -> None: # Main function for testing. numbers = [1, 2, 3] - print("permutations are:", permute(nums)) - print( - "isValid:", - all(list(nums) in permute(numbers) for nums in permutations(numbers)), - ) + print("permutations are:", permute(numbers)) + print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) if __name__ == "__main__": From a6043340f4967911d5c061bbe851682931414e17 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 04:57:18 +0000 Subject: [PATCH 19/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 753ef3e66245..774fe414207e 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,4 +1,6 @@ from itertools import permutations + + # All permutations: def permute(nums: list[int]) -> list[list[int]]: """ @@ -19,10 +21,14 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result + def main() -> None: # Main function for testing. numbers = [1, 2, 3] print("permutations are:", permute(numbers)) - print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) + print( + "isValid:", + all(list(nums) in permute(numbers) for nums in permutations(numbers)), + ) if __name__ == "__main__": From a1c3cd0a6f9655539a6e02a17d2520ea35729efa Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:57:20 +0530 Subject: [PATCH 20/24] Update data_structures/arrays/permutations.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- data_structures/arrays/permutations.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 774fe414207e..0cccf20b796d 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -22,14 +22,10 @@ def permute(nums: list[int]) -> list[list[int]]: return result -def main() -> None: # Main function for testing. +if __name__ == "__main__": numbers = [1, 2, 3] print("permutations are:", permute(numbers)) print( "isValid:", all(list(nums) in permute(numbers) for nums in permutations(numbers)), ) - - -if __name__ == "__main__": - main() From 9cad4b8b5a6033c79961bed45c816c343930ff17 Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:04:09 +0530 Subject: [PATCH 21/24] Update permutations.py --- data_structures/arrays/permutations.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 0cccf20b796d..966815b2cca7 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,6 +1,5 @@ from itertools import permutations - # All permutations: def permute(nums: list[int]) -> list[list[int]]: """ @@ -21,11 +20,7 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result - if __name__ == "__main__": numbers = [1, 2, 3] print("permutations are:", permute(numbers)) - print( - "isValid:", - all(list(nums) in permute(numbers) for nums in permutations(numbers)), - ) + print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers)),) From b192a96aca5f60084cdd39e48e63d8ee2c7ce18f Mon Sep 17 00:00:00 2001 From: Anshraj Shrivastava <42239140+rajansh87@users.noreply.github.com> Date: Wed, 26 Oct 2022 18:04:21 +0530 Subject: [PATCH 22/24] Update permutations.py --- data_structures/arrays/permutations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 966815b2cca7..c93e6c663fef 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -23,4 +23,4 @@ def permute(nums: list[int]) -> list[list[int]]: if __name__ == "__main__": numbers = [1, 2, 3] print("permutations are:", permute(numbers)) - print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers)),) + print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) From b4909710b53d5310dae9a77e2d85a2ec25ccc695 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:35:34 +0000 Subject: [PATCH 23/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/arrays/permutations.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index c93e6c663fef..0cccf20b796d 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,5 +1,6 @@ from itertools import permutations + # All permutations: def permute(nums: list[int]) -> list[list[int]]: """ @@ -20,7 +21,11 @@ def permute(nums: list[int]) -> list[list[int]]: nums.append(n) return result + if __name__ == "__main__": numbers = [1, 2, 3] print("permutations are:", permute(numbers)) - print("isValid:",all(list(nums) in permute(numbers) for nums in permutations(numbers))) + print( + "isValid:", + all(list(nums) in permute(numbers) for nums in permutations(numbers)), + ) From bb480be9ea2683772e42856db47dbc1927dd38f2 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 29 Oct 2022 15:23:33 +0200 Subject: [PATCH 24/24] Update permutations.py --- data_structures/arrays/permutations.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py index 0cccf20b796d..eb3f26517863 100644 --- a/data_structures/arrays/permutations.py +++ b/data_structures/arrays/permutations.py @@ -1,9 +1,7 @@ -from itertools import permutations - - -# All permutations: def permute(nums: list[int]) -> list[list[int]]: """ + Return all permutations. + >>> from itertools import permutations >>> numbers= [1,2,3] >>> all(list(nums) in permute(numbers) for nums in permutations(numbers)) @@ -23,9 +21,6 @@ def permute(nums: list[int]) -> list[list[int]]: if __name__ == "__main__": - numbers = [1, 2, 3] - print("permutations are:", permute(numbers)) - print( - "isValid:", - all(list(nums) in permute(numbers) for nums in permutations(numbers)), - ) + import doctest + + doctest.testmod()