Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mergeSort(alist):
- if len(alist)>1:
- mid = len(alist)//2
- lefthalf = alist[:mid]
- righthalf = alist[mid:]
- mergeSort(lefthalf)
- mergeSort(righthalf)
- i=0
- j=0
- k=0
- while i < len(lefthalf) and j < len(righthalf):
- if lefthalf[i] < righthalf[j]:
- alist[k]=lefthalf[i]
- i=i+1
- else:
- alist[k]=righthalf[j]
- j=j+1
- k=k+1
- while i < len(lefthalf):
- alist[k]=lefthalf[i]
- i=i+1
- k=k+1
- while j < len(righthalf):
- alist[k]=righthalf[j]
- j=j+1
- k=k+1
- f = open('AItext.txt','r+')
- dictionary = []
- for line in f:
- for word in line.split():
- dict_word = ''
- for x in word:
- if x == '.' or x == ',' or x == ';' or x == '!' or x == '(' or x == ')':
- pass
- else:
- if x == '-':
- dictionary.append(dict_word)
- dict_word = ''
- else:
- x = x.lower()
- dict_word = dict_word + x
- if dict_word in dictionary:
- pass
- else:
- dictionary.append(dict_word)
- mergeSort(dictionary)
- print(dictionary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement