diff --git a/anagram.py b/anagram.py index 1fb8057..ff77bc8 100644 --- a/anagram.py +++ b/anagram.py @@ -1,13 +1,16 @@ # Check whether two string is anagram of each other def anagram(a, b): - x = ''.join(sorted(a.lower())).strip() - y = ''.join(sorted(b.lower())).strip() - - if len(x) != len(y) or x != y: + if len(a) != len(b): print('"{}" is not an anagram to "{}"'.format(a, b)) - else: - print('"{}" is an anagram to "{}"'.format(a, b)) + else: + x = ''.join(sorted(a.lower())).strip() + y = ''.join(sorted(b.lower())).strip() + + if x != y: + print('"{}" is not an anagram to "{}"'.format(a, b)) + else: + print('"{}" is an anagram to "{}"'.format(a, b)) if __name__ == '__main__': a = "Tom Marvolo Riddle"