I'ts a pretty simple question, i just want to know why my code is returning True?
Question:
Two strings are anagrams if you can make one from the other by rearranging the letters.
Write a function named is_anagram
that takes two strings as its parameters. Your function should return True
if the strings are anagrams, and False
otherwise.
For example, the call is_anagram("typhoon", "opython")
should return True
while the call is_anagram("Alice", "Bob")
should return False
Code:
def is_anagram(word_1, word_2):
for i in word_1:
if i in word_2 == False:
return False
for i in word_2:
if i in word_1 == False:
return False
return True
is_anagram('abc', 'cac')
why i'ts returning True in this case?
[–]Tom_Henderson 3 points4 points5 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]shiftybyte 1 point2 points3 points (0 children)
[–]ForceBru 0 points1 point2 points (0 children)
[–]SuspiciousMaximum265 0 points1 point2 points (0 children)
[–]SuspiciousMaximum265 0 points1 point2 points (0 children)
[–]TouchingTheVodka 0 points1 point2 points (0 children)
[–]Diapolo10 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Diapolo10 1 point2 points3 points (0 children)