gpt4 book ai didi

python - 如何删除嵌套列表内部的字符串引号

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:30 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com