From 0ea837d86c2186ef2cb6e1b797784ab34b0074da Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Mon, 25 Mar 2019 12:29:07 -0400 Subject: [PATCH] Removed some unnecesary code --- Algorithms.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Algorithms.py b/Algorithms.py index 0ff9444..0d0bf19 100644 --- a/Algorithms.py +++ b/Algorithms.py @@ -221,7 +221,7 @@ def prod(nums: list) -> int: return product #This is a function that creates all permutations of a string and returns a vector of those permutations. -def getPermutations(master: str, num = 0) -> list: +def getPermutations(master: str, num: int = 0) -> list: perms = [] #Check if the number is out of bounds if((num >= len(master)) or (num < 0)): @@ -236,8 +236,6 @@ def getPermutations(master: str, num = 0) -> list: perms += temp #You need to swap the current letter with every possible letter after it #The ones needed to swap before will happen automatically when the function recurses - cnt = 1 - #while((num + cnt) < len(master)): for cnt in range(1, len(master) - num): #Swap two elements master = master[0:num] + master[num + cnt] + master[num + 1 : num + cnt] + master[num] + master[num + cnt + 1:] @@ -246,12 +244,9 @@ def getPermutations(master: str, num = 0) -> list: perms += temp #Swap the elements back master = master[0:num] + master[num + cnt] + master[num + 1 : num + cnt] + master[num] + master[num + cnt + 1:] - #Advance the counter - cnt += 1 #The array is not necessarily in alpha-numeric order. So if this is the full array sort it before returning if(num == 0): perms.sort() - #Return the list return perms