Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import csv
  2. import re
  3. import time
  4.  
  5. question = input("Input your sentence: ")
  6.  
  7. with open('words.csv', 'wt') as myfile:
  8. wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
  9. wr.writerow(question)
  10.  
  11. def conv2pos(*question):
  12. def conv_one(s):
  13. words = s.split()
  14. word_pos = {w:words.index(w) for w in set(words)}
  15. return [word_pos[w] for w in words]
  16.  
  17. return [conv_one(s) for s in question]
  18.  
  19. with open('position.csv', 'wt') as myfile:
  20. wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
  21. wr.writerow(conv2pos(question))
  22. print(conv2pos(question))
  23. print("Success")
  24.  
  25. That is my code. It creates 2 csv files with the positions and words from the user's sentence. I now need to use that info to recreate the sentence
  26.  
  27. words.csv: "h","e","l","l","o"," ","h","i"," ","h","e","l","l","o" Broken I know trying to fix this too.
  28.  
  29. positions.csv: "[0, 1, 0]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement