Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python program to find uncommon words from two strings

# Python3 program to find a list of uncommon words

# Function to return all uncommon words
def UncommonWords(A, B):

	# count will contain all the word counts
	count = {}
	
	# insert words of string A to hash
	for word in A.split():
		count[word] = count.get(word, 0) + 1
	
	# insert words of string B to hash
	for word in B.split():
		count[word] = count.get(word, 0) + 1

	# return required list of words
	return [word for word in count if count[word] == 1]

# Driver Code
A = "Geeks for Geeks"
B = "Learning from Geeks for Geeks"

# Print required answer
print(UncommonWords(A, B))
Comment

PREVIOUS NEXT
Code Example
Python :: python module location 
Python :: how to make a bill in python 
Python :: openpyxl get value from readonly cell 
Python :: append string python 
Python :: python region 
Python :: make parameter optional python 
Python :: remove word from string in python 
Python :: how to make a comment in python 
Python :: sort python 
Python :: pandas count show one column 
Python :: how to generate random number in python 
Python :: program to add first and last digit of a number in python 
Python :: Login script using Python and SQLite 
Python :: Set value of dataframe using condition 
Python :: python any in list 
Python :: multiprocessing in jupyter notebook 
Python :: How can you hide a tkinter window 
Python :: python between inheritance and composition 
Python :: word counter python 
Python :: how to count substring in a string in python 
Python :: sort values within groups pandas dataframe 
Python :: float64 python 
Python :: fibonacci series in python 
Python :: any python 
Python :: how to define variable in python 
Python :: strip characters from a string python 
Python :: python remove dtype from array 
Python :: circular cropping of image in python 
Python :: python filter list with lambda 
Python :: 16 bit floating point numpy 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =