File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #To find the word frequency
2+ str1 = input("enter the string:")
3+ # Words Frequency in String Shorthands
4+ # Using dictionary comprehension + count() + split()
5+ wf = {key: str.count(key) for key in test_str.split()}
6+ print("the original string is" + str(str1))
7+ print("the word frequency" + str(wf))
8+
9+ #To find list of uncommon words
10+ # Function to return all uncommon words
11+ def UncommonWords(A, B):
12+ # count will contain all the word counts
13+ count = {}
14+ # insert words of string A to hash
15+ for word in A.split():
16+ count[word] = count.get(word, 0) + 1
17+ for word in B.split():
18+ count[word] = count.get(word, 0) + 1
19+ # return required list of words
20+ return [word for word in count if count[word] == 1]
21+ A = input("enter the string 1")
22+ B = input("enter the string 2")
23+ print(UncommonWords(A, B))
You can’t perform that action at this time.
0 commit comments