Permalink
Cannot retrieve contributors at this time
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?
Python-Chatbot/Checkings.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (54 sloc)
1.65 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' 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''' |