我有一个代码块,如下所示:
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
如何轻松解决这个问题?感谢帮助
最佳答案
试试这个,我想这就是你想要的。
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
关于python - 如何删除嵌套列表内部的字符串引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53752507/