Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import re
  2. sentence=input('enter sentence')
  3. punctuation=(re.findall(r"[w'"]+|[.,!?;:_-]", sentence))
  4. print(punctuation)
  5. positions = [punctuation.index(x) for x in punctuation]
  6. print(positions)
  7. test1=(",".join(str(i) for i in positions))
  8. words=" ".join(sorted(set(punctuation), key=punctuation.index))
  9. print(words)
  10. with open('1.txt', 'w') as f:#this creates the name of the file called task 2 which will contain my data ad allows the computer to locate the fle and add in the data. The 'w' makes the file writable so i can add in my data, without it displaying an error, using f as a variable.
  11. f.write(str(words))
  12. with open('2.txt', 'w') as f:
  13. f.write(str(test1))
  14. f.close()
  15. openfile=input('what is your file name for the compressed sentence?')
  16. openfile = open(openfile, "r")
  17. print ( openfile.read())
  18. openfile=input('what is your file name for the compressed positions?')
  19. openfile = open(openfile, "r")
  20. print ( openfile.read())
  21.  
  22. openfile = open('1.txt', "r")
  23.  
  24. test=openfile.read()
  25. #print(test)
  26.  
  27. blankarray=[]
  28.  
  29. for i in test.split(" "):
  30. blankarray.append(i)
  31.  
  32. #print(blankarray)
  33.  
  34.  
  35. openfile.close
  36.  
  37. openfile = open('2.txt', "r")
  38.  
  39. test=openfile.read()
  40. #print(test)
  41.  
  42. blankarray2=[]
  43.  
  44. for i in test.split(","):
  45. blankarray2.append(int(i))
  46.  
  47. #print(blankarray2)
  48. openfile.close
  49.  
  50.  
  51. blankstring=""
  52.  
  53. for i in range(len(blankarray2)):
  54. #print(i)
  55. blankstring=blankstring+blankarray[blankarray2[i]] + " "
  56. print(blankstring)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement