我有一个代码块,如下所示:
lst=[67310,0,"May the force be with you"]
print(" ".join(repr(i) for i in lst).replace("'",""))
输出为:
67310 0 May the force be with you
但是,如果我有一个列表,像这样:
lst=[[67310,0,"May the force be with you"],[65310,1,"I'm getting too old for this stuff"]]
for j in lst:
print(" ".join(repr(i) for i in j).replace("'",""))
输出为:
67310 0 May the force be with you
65310 1 "Im getting too old for this stuff"
问题是我想要一个不带引号的输出:
67310 0 May the force be with you
65310 1 I'm getting too old for this stuff
如何轻松解决此问题?感谢您的帮助
答案 0 :(得分:3)
只需尝试一下,我想这就是您想要的。
lst=[[67310,0,"May the force be with you"],[65310,1,"I'm getting too old for this stuff"]]
for j in lst:
print(" ".join(str(i) for i in j).replace("'",""))
# 67310 0 May the force be with you
# 65310 1 Im getting too old for this stuff
答案 1 :(得分:0)
尝试以下方法:
for j in lst:
print(" ".join(repr(i) for i in j).replace('"', ''))
在您的.replace
中,您要替换的是'
,而不是"
。