Skip to content

Commit 5e34b70

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#441 from hitesh-star/patch-1
added remove duplicates words from a sentence
2 parents b39e8ba + 25fed74 commit 5e34b70

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

removeduplicates.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://www.facebook.com/hitesh.parashar.908/posts/109797064227048
2+
# subscribed by hitesh parashar
3+
4+
5+
from collections import Counter
6+
7+
def remov_duplicates(input):
8+
9+
# split input string separated by space
10+
input = input.split(" ")
11+
12+
# joins two adjacent elements in iterable way
13+
for i in range(0, len(input)):
14+
input[i] = "".join(input[i])
15+
16+
# now create dictionary using counter method
17+
# which will have strings as key and their
18+
# frequencies as value
19+
UniqW = Counter(input)
20+
21+
# joins two adjacent elements in iterable way
22+
s = " ".join(UniqW.keys())
23+
print (s)
24+
25+
# Driver program
26+
if __name__ == "__main__":
27+
input = 'Python is great and Java is also great'
28+
remov_duplicates(input)

0 commit comments

Comments
 (0)