只出现过一次
#Uncommon Words from Two Sentences
class Solution(object):
def uncommonFromSentences(self, A, B):
"""
:type A: str
:type B: str
:rtype: List[str]
"""
result = {}
result_real = []
A_List = A.split(' ')
B_List = B.split(' ')
for index in range(len(A_List)):
if A_List[index] not in result:
result[A_List[index]] = 0
else :
result[A_List[index]] += 1
for index in range(len(B_List)):
if B_List[index] not in result:
result[B_List[index]] = 0
else :
result[B_List[index]] += 1
for key in result.keys():
if result[key] == 0:
result_real.append(key)
print(result_real)
return result_real
t = Solution()
A = "apple apple"
B = "banana"
t.uncommonFromSentences(A,B)