Skip to content

Instantly share code, notes, and snippets.

@habina
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save habina/19a729085f14c9d2a3bc to your computer and use it in GitHub Desktop.
Save habina/19a729085f14c9d2a3bc to your computer and use it in GitHub Desktop.
1.3 Given two strings, write a method to decide if one is a permutation of the other.
def permutationString(firstStr, secondStr):
"Return True if the second string is a permutation of the other"
"""If the length of two strings are different,
directly return false
"""
if(len(firstStr) != len(secondStr)):
return False
"Change all characters to lowercase"
fistrStr = firstStr.lower()
secondStr = secondStr.lower()
"Create a list and fill with all characters from first string"
charArray = []
for i in range(len(firstStr)):
charArray.append(firstStr[i])
"Remove all characters from the second string"
for i in range(len(secondStr)):
if(secondStr[i] in charArray):
charArray.remove(secondStr[i])
"Return True if the array is empty"
if(len(charArray) != 0):
print(charArray)
return False
else:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment