Skip to content

Instantly share code, notes, and snippets.

@gr33ndata
Created March 24, 2015 22:43
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 gr33ndata/a098da514144398dd32d to your computer and use it in GitHub Desktop.
Save gr33ndata/a098da514144398dd32d to your computer and use it in GitHub Desktop.
Solving Anagram check problem
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