Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
''' All codes in this file are extracted and editted from https://stackoverflow.com/questions/25798674/python-duplicate-words '''
def isRepeat(sentence):
words = sentence.split(" ")
words.sort() # ascending sorting
# keep user original input
words_copied = sentence.split(" ")
words_copied.sort()
wordL=[]
'''Copied codes to loop through the sentence given.'''
for word in words[0:len(words)-1]:
count = 0
while True:
try:
index = words_copied.index(word)
count += 1
del words_copied[index]
except ValueError:
if count > 1:
wordL.append([word,count])
break
'''Copied code ends'''
if wordL != []:
repeat=True
else:
repeat=False
return repeat
def CountRepeat(sentence):
words = sentence.split(" ")
words.sort() # ascending sorting
# keep user original input
words_copied = sentence.split(" ")
words_copied.sort()
wordL={}
for word in words[0:len(words)-1]:
count = 0
while True:
try:
index = words_copied.index(word)
count += 1
del words_copied[index]
except ValueError:
if count > 1:
wordL.update({word:count})
break
if wordL != []:
repeat=True
else:
repeat=False
return wordL
'''Debugger'''
#sentence=input('Enter your sentence : ')
#print(isRepeat(input()))
#print(CountRepeat(sentence))
'''Debugger ends'''