小编Shu*_*ami的帖子

去除特定字符之前的部分字符串,以防该字符出现多次

我需要从字符之前出现的部分去除字符串':',其中':'可能出现多次。例如:

input: 'Mark: I am sending the file: abc.txt'
output: 'I am sending the file: abc.txt'
Run Code Online (Sandbox Code Playgroud)

我的功能是这个(Python代码)

def process_str(in_str):
    str_list = in_str.split(':')[1:]
    out_str = ''
    for each in str_list:
        out_str += each
    return out_str
Run Code Online (Sandbox Code Playgroud)

我得到的输出'I am sending the file abc.txt'没有第二个':'. 有没有办法纠正这个问题?也可以使这段代码在时间和空间复杂度上更有效吗?

python python-2.7 python-3.x

2
推荐指数
1
解决办法
5123
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1