尝试标记化和剥离逗号值
的当前输出def clean(string):
result = ""
for i,char in enumerate(line):
if char == " ":
if string[i+1].isdigit() or string[i+1] == " ":
continue
result += char
return result
纬度+41.136778,-95.948622 65.000000红色 纬度+41.136778,-95.948622 65.000000红色 纬度+41.136778,-95.948622 65.000000蓝色
纬度+41.136778,-95.948622 65.000000红色
如果我尝试这样在字符串中添加逗号:
def clean(string):
result = ""
for i,char in enumerate(line):
if char == " ":
if string[i+1].isdigit() or or string[i+1] + "," string[i+1] == " ":
continue
result += char
return result
我得到以下信息:
纬度+41.137342,经度= -95.947951bar = 65.000000foo = 23.849165secscolor =红色纬度+41.137338,经度= -95.947936bar = 65.000000foo = 0.036936secscolor =蓝色纬度+41.137338,经度= -95.947936bar = 65.000000foo = 58.715930secscolor =蓝色
所需的输出:
纬度+41.136778经度栏-95.948622 foo 65.000000颜色蓝色 纬度+41.136778经度栏-95.948622 foo 65.000000颜色红色
谢谢
答案 0 :(得分:1)
不确定是否完全理解,但我认为您可能正在寻找以下内置功能:
return string.replace(",", " ")
PS:您可以多次使用它:
return string.replace(",", " ").replace("=", " ")