Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions week10/counting_anagrams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Author: Kayode
---

Counting Anagrams

Have the function CountingAnagrams(str) take the str parameter and determine how many anagrams exist in the string. An anagram is a new word that is produced from rearranging the characters in a different word, for example: cars and arcs are anagrams. Your program should determine how many anagrams exist in a given string and return the total number. For example: if str is "aa aa odg dog gdo" then your program should return 2 because "dog" and "gdo" are anagrams of "odg". The word "aa" occurs twice in the string but it isn't an anagram because it is the same word just repeated. The string will contain only spaces and lowercase letters, no punctuation, numbers, or uppercase letters.


Examples
Input: "aa aa odg dog gdo"
Output: 2

Input: "a c b c run urn urn"
Output: 1
28 changes: 28 additions & 0 deletions week10/counting_anagrams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def counting_anagrams(arr):
arr2= arr.split()
anna= 0

for i,j in enumerate(arr2):
for k,l in enumerate(arr2):
if j == l and i != k:
arr2.pop(k)

for i in arr2:
for j in arr2:
if len(i) == len(j):
if i != j:
for k in i:
if k in j:
i.replace(k, '')
else:
break
else:
arr2.remove(j)
anna= anna + 1

print(anna)



# counting_anagrams("aa aa odg dog gdo")
counting_anagrams("a c b c run urn urn")