Skip to content

Commit b195af0

Browse files
Create string_programs
1 parent 830f133 commit b195af0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

python/string_programs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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))

0 commit comments

Comments
 (0)