Words Only Once
When comparing two texts, you may need to find words that appear in only one place and nowhere else. Write a function uncommon_words that receives two space-separated sentences, s1 and s2. A word is uncommon if it appears exactly once in one sentence and does not appear in the other sentence at all. Return the uncommon words sorted alphabetically.
Примеры
Ввод
"this apple is sweet", "this apple is sour"Вывод
["sour", "sweet"]Ввод
"apple apple", "banana"Вывод
["banana"]Ввод
"a b c", "a b c"Вывод
[]Нужно реализовать
def uncommon_words(s1: str, s2: str) -> list[str]:
Теги
stringshashmapdict
Accedi per vedere la cronologia degli invii
AccediAccedi per usare l'AI Mentor
AccediVisible tests
1
Input
"this apple is sweet", "this apple is sour"Expected
["sour","sweet"]2
Input
"apple apple", "banana"Expected
["banana"]3
Input
"a b c", "a b c"Expected
[]4
Input
"one", "two"Expected
["one","two"]5
Input
"fly me to the moon", "moon me"Expected
["fly","the","to"]6
Input
"", "hello world"Expected
["hello","world"]Focus radio
Paused · SomaFM · Fluid