MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / anagramSolution3

Method anagramSolution3

AnagramDetection.py:52–65  ·  view source on GitHub ↗
(self, s1, s2)

Source from the content-addressed store, hash-verified

50 # 比较两个set, 如果不相等直接返回false
51 # 如果两个set相等, 比较每个set中字符在相应list中的个数, 个数不同返回false
52 def anagramSolution3(self, s1, s2):
53 alist1 = list(s1)
54 alist2 = list(s2)
55
56 aset1 = set(alist1)
57 aset2 = set(alist2)
58
59 if aset1 != aset2:
60 return False
61 else:
62 for ch in aset1:
63 if alist1.count(ch) != alist2.count(ch):
64 return False
65 return True
66
67s1 = 'abcde'
68s2 = 'acbde'

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected