Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从字符串列表中删除不需要的字符?_Python_Python 3.x - Fatal编程技术网

Python 如何从字符串列表中删除不需要的字符?

Python 如何从字符串列表中删除不需要的字符?,python,python-3.x,Python,Python 3.x,只是想为我的场景找到合适的解决方案。假设我有一个包含2个元素的列表,如下所示: old_str = ['https://www[dot]exabeam[dot]com','https://www[dot]google[dot]com/#q=exa+beam'] 我希望输出为['www.exabeam.com','www.google.com'] 我可以很好地使用下面的逻辑将“[dot]”替换为“.” new_str= [] for new_char in old_str: replac

只是想为我的场景找到合适的解决方案。假设我有一个包含2个元素的列表,如下所示:

old_str = ['https://www[dot]exabeam[dot]com','https://www[dot]google[dot]com/#q=exa+beam']
我希望输出为
['www.exabeam.com','www.google.com']

我可以很好地使用下面的逻辑将“[dot]”替换为“.”

new_str= []
for new_char in old_str:
    replaced_str = new_char.replace('[dot]', '.')
    new_str.append(replaced_str)
print(new_str)
输出为:

[['https://www.exabeam.com'], ['https://www.google.com/#q=exa+beam']]
那么,如何实现预期的产出呢?请帮忙

谢谢

使用:

输出:

['www.exabeam.com', 'www.google.com']

它总是“https://”吗?是的,无论如何@Chris的解决方案很有魅力。谢谢你显示的输出不正确,你显示的代码与实际问题无关。嗨,是的,我知道。我的意思是在我问问题之前我必须做调查。我就是这么做的,我知道我的程序效率很低。谢谢你
['www.exabeam.com', 'www.google.com']