Given two sentences as strings A and B. The task is to return a list of all uncommon words. A word is uncommon if it appears exactly once in any one of the sentences, and does not appear in the other sentence.
Note: A sentence is a string of space separated words. Each word consists only of lowercase letters.
Input : A = "Geeks for Geeks" B = "Learning from Geeks for Geeks" Output : ['Learning', 'from'] Input : A = "apple banana mango" B = "banana fruits mango" Output : ['apple', 'fruits']
Approach: Every uncommon word occurs exactly once in any one of the strings. So, we make a hash to count the number of occurrences of every word, then return list of words that occurs exactly once.
Below is the implementation of above approach:
- Find uncommon characters of the two strings
- Concatenated string with uncommon characters of two strings
- Python program to count words in a sentence
- Python program to print even length words in a string
- Python | Find k longest words in given list
- Concatenated string with uncommon characters in Python
- Python | Program to accept the strings which contains all vowels
- Sorting array of strings (or words) using Trie
- Palindrome pair in an array of words (or strings)
- Python Program to Count number of binary strings without consecutive 1's
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Python Program for Program to find area of a circle
- Python Program for Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Python | Tokenizing strings in list of strings
- Possible Words using given characters in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.