Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. def mergeSort(alist):
  2. if len(alist)>1:
  3. mid = len(alist)//2
  4. lefthalf = alist[:mid]
  5. righthalf = alist[mid:]
  6.  
  7. mergeSort(lefthalf)
  8. mergeSort(righthalf)
  9.  
  10. i=0
  11. j=0
  12. k=0
  13. while i < len(lefthalf) and j < len(righthalf):
  14. if lefthalf[i] < righthalf[j]:
  15. alist[k]=lefthalf[i]
  16. i=i+1
  17. else:
  18. alist[k]=righthalf[j]
  19. j=j+1
  20. k=k+1
  21.  
  22. while i < len(lefthalf):
  23. alist[k]=lefthalf[i]
  24. i=i+1
  25. k=k+1
  26.  
  27. while j < len(righthalf):
  28. alist[k]=righthalf[j]
  29. j=j+1
  30. k=k+1
  31.  
  32.  
  33. f = open('AItext.txt','r+')
  34. dictionary = []
  35. for line in f:
  36. for word in line.split():
  37. dict_word = ''
  38. for x in word:
  39. if x == '.' or x == ',' or x == ';' or x == '!' or x == '(' or x == ')':
  40. pass
  41. else:
  42. if x == '-':
  43. dictionary.append(dict_word)
  44. dict_word = ''
  45. else:
  46. x = x.lower()
  47. dict_word = dict_word + x
  48. if dict_word in dictionary:
  49. pass
  50. else:
  51. dictionary.append(dict_word)
  52.  
  53. mergeSort(dictionary)
  54. print(dictionary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement