0

So im making a anagram detector that reads all the words in a string.
I already have the anagram funktion working (returning true if it is a anagram, and false otherwise)

But i am having trouble making a loop that reads all the words in the string, and returning the anagram words.

For now i have, where "is_anagram()" is the funktion telling if 2 words are anagrams or not.

def anagram_solver(string_of_words):
    word_list = string_of_words.split()
    index1 = 0
    index2 = 1
    anagram_liste = []
    for word in word_list:
        print(word)
        if is_anagram(word, word_list[0]):
            anagram_liste.append(word)
            index1 +=1
                
        else:
            index1 += 1
    
            
    return anagram_liste

print(anagram_solver('halb mojn bhal njom ff albh whats'))

A little hint on how to proceed?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Lomholdt
0

First search for "Python anagram" at Daniweb using the search box at the top of the page. That will give you several techniques for using a list of words and will not require us to answer the same question over and over.

## this will always be true on the first pass
        if is_anagram(word, word_list[0]):   

  
        # these lines do nothing as index1 is never used
           index1 +=1
 
        else:
            index1 += 1

Edited by woooee: n/a

0

I think you misunderstood my question.

What i need to know is, how to make a loop that at first looks at:

a and a
a and b
a and c

then looks at

b and a
b and b
b and c

and so on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.