forked from vglug/ProgrammingLogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_programs
More file actions
23 lines (22 loc) · 828 Bytes
/
string_programs
File metadata and controls
23 lines (22 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#To find the word frequency
str1 = input("enter the string:")
# Words Frequency in String Shorthands
# Using dictionary comprehension + count() + split()
wf = {key: str.count(key) for key in test_str.split()}
print("the original string is" + str(str1))
print("the word frequency" + str(wf))
#To find 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
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]
A = input("enter the string 1")
B = input("enter the string 2")
print(UncommonWords(A, B))