Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import re
- import time
- question = input("Input your sentence: ")
- with open('words.csv', 'wt') as myfile:
- wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
- wr.writerow(question)
- def conv2pos(*question):
- def conv_one(s):
- words = s.split()
- word_pos = {w:words.index(w) for w in set(words)}
- return [word_pos[w] for w in words]
- return [conv_one(s) for s in question]
- with open('position.csv', 'wt') as myfile:
- wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
- wr.writerow(conv2pos(question))
- print(conv2pos(question))
- print("Success")
- 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
- words.csv: "h","e","l","l","o"," ","h","i"," ","h","e","l","l","o" Broken I know trying to fix this too.
- positions.csv: "[0, 1, 0]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement