Created
March 24, 2015 22:43
-
-
Save gr33ndata/a098da514144398dd32d to your computer and use it in GitHub Desktop.
Solving Anagram check problem
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
def dict_load(s): | |
d = {} | |
for c in s: | |
if c == " ": | |
pass | |
else: | |
d[c] = d.get(c, 0) + 1 | |
return d | |
def dict_unload(s, d): | |
for c in s: | |
if c == " ": | |
pass | |
elif d.get(c, 0) > 1: | |
d[c] = d[c] - 1 | |
elif d.get(c, 0) == 1: | |
d.pop(c) | |
else: | |
return {'some': 'rubbish'} | |
return d | |
def anagram_detection(s1,s2): | |
if not dict_unload(s2, dict_load(s1)): | |
return True | |
else: | |
return False | |
s1 = raw_input("Please enter first string: ").lower() | |
s2 = raw_input("Please enter second string: ").lower() | |
if anagram_detection(s1,s2): | |
print "Anagram." | |
else: | |
print "Not Anagram." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment