I have a large text file with words that are interspersed with numbers and two types of characters, a '|' and '.'. I searched on StackOverflow and found how to take this string and only retain letters. For example, if
old_fruits='apple|0.00|kiwi|0.00|0.5369|-0.2437|banana|0.00|pear'
then
re.sub("[^A-Za-z]","",old_fruits)
would return
'applekiwibananapear'
I’m trying to write these words out to a file with one word on each line, followed by a newline and then the next word, like:
apple
kiwi
banana
pear
Any thoughts or pointing in the right direction is appreciated.
Try this: