首页 > 解决方案 > 如何删除嵌套列表中的字符串引号

问题描述

我有一个代码块,如下所示:

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

我怎样才能轻松解决这个问题?感谢帮助

标签: pythonpython-3.x

解决方案


试试这个,我想这就是你想要的。

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

推荐阅读