Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

Assume a list, where I have a list of strings:

["car", "tree", "boy", "girl", "arc"...]

What would it be a good idea for me to do to discover anagrams in that list? For instance (car, arc). I had a go at utilizing for loop for each string and I utilized if to disregard strings in various lengths however I can't get the correct outcome. 

How might I go over each letter in the string and contrast it with others in the list in various request? 

I have also read a few comparative inquiries, yet the appropriate responses were excessively exceptional. I can't import anything and I can just utilize essential functions.

1 Answer

0 votes
by (26.4k points)

Try the following code:

def isAnagram(str1, str2):

    str1_list = list(str1)

    str1_list.sort()

    str2_list = list(str2)

    str2_list.sort()

    return (str1_list == str2_list)

Wanna become a python expert? Come and join the python certification course and get certified.

Related questions

Browse Categories

...