我有一个嵌套的 list_3 ,它看起来像:
[['Company OverviewCompany: HowSector: SoftwareYear Founded: 2010One Sentence Pitch: Easily give and request low-quality feedback with your team to achieve more togetherUniversity Affiliation(s): Duke$ Raised: $240,000Investors: Friends & familyTraction to Date: 10% of monthly active users (MAU) are also active weekly'], [['Company OverviewCompany: GrubSector: SoftwareYear Founded: 2018One Sentence Pitch: Find food you likeUniversity Affiliation(s): Stanford$ Raised: $340,000Investors: Friends & familyTraction to Date: 40% of monthly active users (MAU) are also active weekly']]]
我想使用正则表达式在每个连接的单词之间添加一个逗号,后跟一个空格,即(HowSector:,SoftwareYear,2010One),到目前为止,我已经尝试编写一个 re.sub 代码来做,通过选择所有没有的字符空白并替换它,但遇到了一些问题:
for i, list in enumerate(list_3):
list_3[i] = [re.sub('r\s\s+', ', ', word) for word in list]
list_33.append(list_3[i])
print(list_33)
错误:
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
我希望输出为:
[['Company Overview, Company: How, Sector: Software, Year Founded: 2010, One Sentence Pitch: Easily give and request low-quality feedback with your team to achieve more together University, Affiliation(s): Duke, $ Raised: $240,000, Investors: Friends & family, Traction to Date: 10% of monthly active users (MAU) are also active weekly'],[...]]
任何想法如何使用正则表达式来做到这一点?