是的,可以通过使用字符串的replace方法来实现在列表中字符串的空格之间插入'-'。下面是一个示例代码:
# 假设有一个字符串列表
string_list = ['Hello World', 'Goodbye World']
# 使用列表推导式和replace方法在空格之间插入'-'
new_list = [string.replace(' ', '-') for string in string_list]
# 打印结果
print(new_list)
输出:
['Hello-World', 'Goodbye-World']
在这个示例中,我们使用了列表推导式来遍历字符串列表中的每个字符串。然后,使用replace方法将空格替换为'-'。最后,生成了一个新的带有插入'-'的字符串列表。
领取专属 10元无门槛券
手把手带您无忧上云