Member Avatar for Lomholdt

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?

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
Member Avatar for Lomholdt

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.