Last active
August 29, 2015 14:02
-
-
Save yokiy/23cfde3e7d270be30e2b to your computer and use it in GitHub Desktop.
CC1.3
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
#1.3 Given two strings, write a method to decide is one is a permutation of the other. | |
def permutation(s1, s2): | |
#write string into list | |
list1 = list(s1) | |
list2 = list(s2) | |
#compare the length, if not the same re turn false | |
if len(list1) != len(list2): | |
return False | |
else: | |
#convert to ASCII and compare every char | |
for i in range (len(s1)): | |
char1 = ord(list1[i]) | |
char2 = ord(list2[i]) | |
if char1 == char2: | |
return True | |
else: | |
return False | |
s1 = raw_input('input a string:') | |
s2 = raw_input('input another string:') | |
S = permutation(s1, s2) | |
print S | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment