Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wordlist = []
- def analyse(text):
- i = 0
- lastword = 0
- for char in text:
- i = i + 1
- if char == " ":
- word = text[lastword: i - 1]
- lastword = i
- wordlist.append(word)
- elif i == len(text):
- word = text[lastword: i]
- lastword = i
- wordlist.append(word)
- return wordlist
- def sortlist(list):
- latestword = ''
- amountlist = []
- sortedlist = sorted(list)
- for word in sortedlist:
- i = 1
- if word == latestword:
- amountlist[len(amountlist) - 1] = amountlist[len(amountlist) - 1] + 1
- lastestword = word
- else:
- amountlist.append(i)
- latestword = word
- return amountlist
- def duplicates(list):
- i = 0
- lastword = ''
- finallist = []
- for word in list:
- if word == lastword:
- i = i + 1
- else:
- finallist.append(word)
- lastword = word
- return finallist
- def mostusedwords(numbers, list):
- while len(numbers) > 0:
- index = numbers.index(max(numbers))
- print (list[index] + " times " + str(numbers[index]))
- numbers.remove(numbers[index])
- list.remove(list[index])
- def finalise(string):
- # the number of times each words is entered
- numbersinlist = sortlist(analyse(text))
- #the words according to the above list
- listnodups = duplicates(sorted(analyse(text)))
- return mostusedwords(numbersinlist, listnodups)
- text = 'she sells sea shells by the sea shore'
- finalise(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement