本题注意点:先化简(合并A、B) ,再求值
import numpy as np
def uncommonFromSentences(A, B):
"""
:type A: str
:type B: str
:rtype: List[str]
"""
C = (A + ' ' + B).split(' ')
ans = []
for word in C:
if C.count(word) == 1:
ans.append(word)
return ans
# samples:
A, B = "this apple is sweet", "this apple is sour"
print(uncommonFromSentences(A, B))
A, B = "apple apple", "banana"
print(uncommonFromSentences(A, B))