Link to home
Start Free TrialLog in
Avatar of IT
IT

asked on

how to split attached words and slang look up in a text file in python?

I have a text file which has multiple attached words like RainyDay, PlayingInTheCold etc. These words can be split into normal forms using regex to make them into meaningful words.
import re, string, html
with open("1.txt", "r") as fin, open("2.txt", "w") as fout:
    for text in fin:
        words = text.split()
        cleaned = " ".join(re.findall('[A-Z][^A-Z]*', words))
        fout.write(cleaned)

Open in new window

error: User generated imageAlso, there are many slang words like helo, luv which should be converted to hello, love. I am trying like this
with open("1.txt", "r") as fin, open("2.txt", "w") as fout:
    for text in fin:
        words = text.split()
        words = slang_loopup(words)
        text = ' '.join(words)
        fout.write(cleaned)

Open in new window

I tried _slang_loopup() also but same NameError
error is: User generated image
Can someone please help me?
Thanks
SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IT
IT

ASKER

Thanks pepr. Can someone please also throw some insight on how to separate the attached words?
Actually, I think it should work but not working.
cleaned = " ".join(re.findall('[A-Z][^A-Z]*', words))

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial