Skip to content

Instantly share code, notes, and snippets.

@007bsd
Last active November 12, 2017 12:31
Show Gist options
  • Select an option

  • Save 007bsd/81f2dc70ad7af7e4709298796706114a to your computer and use it in GitHub Desktop.

Select an option

Save 007bsd/81f2dc70ad7af7e4709298796706114a to your computer and use it in GitHub Desktop.
Anagrams code for python
import string
def ara_anagrams():
str1 = input("Please input your first string : ")
str2 = input("Please input your second string : ")
exclude = sorted(set(string.punctuation))
str1 = ''.join(ch for ch in str1 if ch not in exclude)
str2 = ''.join(ch for ch in str2 if ch not in exclude)
if ''.join(sorted(set(str1.replace(" ", "").lower().strip()))) == ''.join(
sorted(set(sorted(str2.replace(" ", "").lower().strip())))):
return True
else:
return False
print(ara_anagrams())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment