我是python的新手,我有一个文本文件,需要在其中连接()中的字符串并在concat之后删除。你知道吗
你知道吗文本.txt你知道吗
Car(skoda,benz,bmw,audi)
The above mentioned cars are sedan type and gives long rides efficient
......
Car(Rangerover,Hummer)
SUV cars are used for family time and spacious.
期望输出
Car(skoda,benz,bmw,audi,Rangerover,Hummer)
The above mentioned cars are sedan type and gives long rides efficient
......
SUV cars are used for family time and spacious.
这里的车应该添加到括号内的第一辆车,然后删除我连接的行。你知道吗
编码:
f_in=open("text.txt", "r")
in_lines=f_in.readlines()
out=[]
for line in in_lines:
list_values=line.split()
for 'Car' in line:
Car[i]=eval(list_values[i])
if Car[i] in line:
str(Car+Car[i]) #i m stuck and my overall logic is getting worse'
请帮我弄到想要的东西输出.due由于缺乏经验,我不知道最简单的方法这个。答案将不胜感激。你知道吗
棘手的替换
搜索:
替换:
在the Regex Demo中,请参见底部的替换。你知道吗
如果有两个以上的Car定义,则运行此替换,直到结果字符串与原始字符串相同。你知道吗
Python代码示例
您可以使用re查找所有汽车,然后写下不包括带汽车的行:
它输出:
相关问题 更多 >
编程相关推荐