main.py
Python
x
20
20
1
string = "Small brown bug bit a small brown dog on his small brown nose";
2
3
#Converts the string into lowercase
4
string = string.lower();
5
6
#Split the string into words using built-in function
7
words = string.split(" ");
8
9
print("Duplicate words in a given string : ");
10
for i in range(0, len(words)):
11
count = 1;
12
for j in range(i+1, len(words)):
13
if(words[i] == (words[j])):
14
count = count + 1;
15
#Set words[j] to 0 to avoid printing visited word
16
words[j] = "0";
17
18
#Displays the duplicate word if count is greater than 1
19
if(count > 1 and words[i] != "0"):
20
print(words[i]);