@nogood/Anagram Tester with Functional-Style Quicksort
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
21
22
23
24
25
26
def quickSort (word):
    if len(word) > 0:
        #defines the pivot value as k
        k = word[0]
        #makes a list of all values in the list after k less than k
        lower = list(filter(lambda x: x < k, word[1:]))
        #same as above, but > or = to k
        higher = list(filter(lambda x: x >= k, word[1:])) 
        #put k between the list of value less than and greater than k, then sort those lists
        return quickSort(lower) + [k] + quickSort(higher)
    else:
        return [] #an empty list is already sorted

def isAnagramOf (word1, word2):
    #takes away spaces, makes upper case
    word1 = word1.replace(" ","").upper()
    word2 = word2.replace(" ","").upper()
    #words cannot be anagrams if they have a different # of letters
    if len(word1) != len(word2):
        return 0
    #sort each word, if they are the same sorted, they are anagrams
    if quickSort(word1) == quickSort(word2):
        return 1
    else:
        return 0
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux