Write a function to find common words from two strings


Topic: Write a function to find common words from two strings

Solution

def commonWords(str1, str2): 
  
    count = {} 
      
    for word in str1.split(): 
        count[word] = count.get(word, 0) + 1
      
    for word in str2.split(): 
        count[word] = count.get(word, 0) + 1
  
    return [word for word in count if count[word] > 1]



List all Python Programs