python - File position and word splitter -
i have program that
- takes text file several sentences
- asks user if want compress/decompress file.
- if compress chosen, sentence have unique words , positions of these words needed recreate sentence again.
- if decompress chosen, compressed text file need found , using position list given , unique words - decompressed - several sentences in files need on separate lines.
here code have managed create. subroutine , it's rather faulty.
uniquewords = [] positions = [] file = def valchoice(): choice = (" ") while choice not in ["compress", "decompress"]: choice = input("choose compress or decompress").lower() if choice not in ["compress", "decompress"]: print("please input compress or decompress") finalchoice = valchoice() if finalchoice = ("compress"): print("this confused..") elif finalchoice = ("decompress"): print("this confused..")
what wrong code? how can fix it?
with caveat above, i'll take shot @ think you're asking.
to compress file, iterate through input words. store each word reference in dictionary: word key, , position value. if word in dictionary, add new position reference existing list of references.
decompression works in reverse: make sequence of positions , words. sort sequence ascending order. concatenate words make original text.
is level of need right now?
Comments
Post a Comment