python替换符号的代码,Python在引号中2个单词之间替换符号

trying to replace comma between 2 words Durango and PC in the second line by & and then remove the quotes " as well. Same for third line with Orbis and PC I would like to retain the rest of the lines using Python:

2,SIN-Rendering,Core Tech - Rendering,PC,147,Reopened

2,Kenny Chong,Core Tech - Rendering,"Durango, PC",55,Reopened

3,SIN-Audio,AAA - Audio,"Orbis, PC",13,Open

...

...

...

Like these, there can be 100 lines in my sample. So the expected output is:

2,SIN-Rendering,Core Tech - Rendering,PC,147,Reopened

2,Kenny Chong,Core Tech - Rendering, Durango & PC,55,Reopened

3,SIN-Audio,AAA - Audio, Orbis & PC,13,Open

...

...

...

So far, I could think of reading line by line and then if the line contains quote replace it with no character but then replacement of symbol inside is something I am stuck with.

How to achieve this, any suggestion? Learning Python.

解决方案

Something like below:

st = "2,Kenny Chong,Core Tech - Rendering,\"Durango, PC\",55,Reopened"

res = re.sub(r'\"(.*),\ (.*)\"',lambda x : (" & ").join(re.findall(r'\"(.*),\ (.*)\"', st)[0]),st)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值