我有一个字符串列表
lst = ["/foo/dir/c-.*.txt","/foo/dir2/d-.*.svc","/foo/dir3/es-.*.info"]
我有前缀字符串:
/root
是否有任何python方法将前缀字符串添加到列表中的每个元素
因此最终结果如下所示:
lst = ["/root/foo/dir/c-.*.txt","/root/foo/dir2/d-.*.svc","/root/foo/dir3/es-.*.info"]
如果可以在不迭代和创建新列表的情况下完成
Tags:
已使用:
使用列表理解和字符串连接:
我不确定pythonic,但这也是可能的方式
这里是列表comp和mapList comprehension vs map之间的比较
也要感谢@chris rands在没有lambda的情况下学会了更多的方法
相关问题 更多 >
编程相关推荐