它不是在 python 字符串中

it's instead of it's in python string

我的 python 字符串由 ' 而不是 '(单引号)组成。我目前的 objective 是扩展复合词,如 It's to It is,Haven't to Have not。

"This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better."

上面的语句是我一直试图转换的句子的一个例子。

有人可以建议一种将其转换为字符串格式的方法吗?

text = "This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better."
d_contraction = {"I'm":"I am","wouldn't":"would not","I've":"I have"}
updated_text = text.replace(''', "'") 
print(updated_text)
for k,v in d_contraction.items():
    updated_text = updated_text.replace(k,v) 
print(updated_text)

输出:

This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better.

This has been great for me. I have been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that would not go away no matter what I took. I am still a little sleepy during the day, but I know that will get better.

以上代码适用于您提供的文本。基本上,您必须创建一个包含所有可能的缩略示例的字典 - they'll、ther're 等。