python - I need some assistance writing to a excel file -
i programming task in user enter sentence (no punctuation), , program store words in list, , replace each word position of word in list created. not have of idea how approach this, new python, assuming should first store words in excel database , position them in list. if have appreciate it, thanks.
for more information task, view screenshot:task details
here quick example how it. remember own work, use learning.
sentence = input("write sentence: ") sentence_array = sentence.lower().split(" ") # split lowercased sentence array individuals = [] # list individual words x in range(0, len(sentence_array)): # loop find individual words if sentence_array[x] not in individuals: # if word not picked already... individuals.append(sentence_array[x]) # ...append individuals list positions = [] # list contains positions of words x in range(0, len(sentence_array)): # loop append positions list positions.append(individuals.index(sentence_array[x]) + 1) # appending indexes of words, notice +1 open("result file.txt", "w") f: # write results file x in range(0, len(positions)): # loop write indexes if x == len(positions)-1: # if last position, write line break instead of comma f.write("%s\n" % positions[x]) else: f.write("%s," % positions[x]) y in range(0, len(individuals)): # loop write words if y == len(individuals)-1: # if last word, write line break instead of comma f.write("%s\n" % individuals[y]) else: f.write("%s, " % individuals[y])
output can viewed in result file.txt
Comments
Post a Comment