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

标签 python python-3.x

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

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/

相关文章:

python - 找出列表中每个项目的对象类型的最佳方法

python - 尽管有 -O(优化)标志,仍保持断言

java - Python3 : how to run java class file from python

python - 什么时候使用迭代器,什么时候使用生成器?

python - 更改 pyinstaller 可执行文件的 Stanza 模型目录

python - 将向量 (float4) kernell 参数传递给 OpenCL (Python)

python - 解码 JSON 字符串并插入 SQL 数据库 (sqlite3)

Python ctypes,将 c_void_p 作为输出参数传递给 c 函数

python - Python2 PriorityQueue 和 Python3 PriorityQueue 的 put 方法有什么区别吗?

python-3.x - PyTorch 和 CUDA 驱动程序