-
Code def is_anagram(s1, s2): n1 = map(ord, s1) n2 = map(ord, s2) return sum(n1) == sum(n2) and sorted(n1) == sorted(n2) and len(s1) == len(s2)
Test Cases import codewars_test as test from solution import is_anagram .describe("Example") def test_group(): .it("test case 1: is Anagram True") def test_case(): true_samples = ( (('listen', 'silent'), True), (('race', 'care'), True), (('night', 'thing'), True),) for s, e in true_samples: test.assert_equals(is_anagram(s[0], s[1]), e) .it("test case 2: is Anagram False") def test_case(): false_samples = ( (('abcd', 'abc'), False), (('anagram', 'nag a ram'), False), (('night', 'things'), False),) for s, e in false_samples: test.assert_equals(is_anagram(s[0], s[1]), e)
Output:
-
Code - def is_anagram(s1, s2):
n1 = [ord(i) for i in s1]n2 = [ord(i) for i in s2]- n1 = map(ord, s1)
- n2 = map(ord, s2)
- return sum(n1) == sum(n2) and sorted(n1) == sorted(n2) and len(s1) == len(s2)
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}