aboutsummaryrefslogtreecommitdiff
path: root/challenge-307/eric-cheung/python/ch-2.py
blob: 6d867fd2395ac1df10a24a718222b100dc708b7a (plain)
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
## Ref.:
## https://www.geeksforgeeks.org/python-sorted-check-two-strings-anagram-not/

def IsAnagrams (strInput_01, strInput_02):
    return (sorted(strInput_01) == sorted(strInput_02))

## arrWords = ["acca", "dog", "god", "perl", "repl"]  ## Example 1
arrWords = ["abba", "baba", "aabb", "ab", "ab"]  ## Example 2

## arrIndxToDel = []
## for nIndx in range(len(arrWords) - 2, -1, -1):
    ## if IsAnagrams (arrWords[nIndx], arrWords[nIndx + 1]):
        ## arrIndxToDel.append(nIndx)

arrIndxToDel = [nIndx for nIndx in range(len(arrWords) - 2, -1, -1) if IsAnagrams (arrWords[nIndx], arrWords[nIndx + 1])]

## print (arrIndxToDel)

## for nIndx in arrIndxToDel:
    ## del arrWords[nIndx]

## print (len(arrWords))

print (len(arrWords) - len(arrIndxToDel))