python - 如何删除嵌套列表中的字符串引号
问题描述
我有一个代码块,如下所示:
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 - Json 加载错误解析
- jquery - Bootstrap 3 - 使用 jQuery 从动态加载的 li 中删除 class="disabled"
- python - pandas Dataframe 持续下降的列值
- c# - C# 将类派生为数组
- ios - 控制台错误:无效的 Firebase 数据集值无法存储对象
- python - 如何在 iPython / Jupyter Notebook 中调整 SVG 图形的大小/重新缩放?
- capybara - Capybara:定位 iframe
- python - 无法在 scrapy 中创建项目说 dll 加载失败
- android - 未使用房间的项目中房间的运行时异常
- tensorflow - 如何扁平化 Dense 层的 RNN 输出?