@asicdude/anagram_detector
Python3

No description

repl talk
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def are_anagrams(a,b):
    letters = {}
    for c in a:
        if c.isupper():
            letters[c] = letters.get(c, 0) + 1
            
    for c in b:
        if c.isupper():
            letters[c] = letters.get(c, 0) - 1

    if any(letters.values()):
        return 0
    else:
        return 1
        
print("\""+"BRITNEY SPEARS"+"\"", "\""+"PRESBYTERIANS"+"\"", are_anagrams("BRITNEY SPEARS", "PRESBYTERIANS") )
print("\""+"DEDUCTION"+"\"", "\""+"DISCOUNTED"+"\"", are_anagrams("DEDUCTION", "DISCOUNTED") )
print("\""+"CLINT EASTWOOD"+"\"", "\""+"OLD WEST ACTION"+"\"", are_anagrams("CLINT EASTWOOD", "OLD WEST ACTION") )
print("\""+"DICTIONARIES"+"\"", "\""+"NEAR IODIOTIC"+"\"", are_anagrams("DICTIONARIES", "NEAR IODIOTIC") )
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux