python - 将两个列表加入到 2 个元素的元组中
问题描述
我有以下数组:
info = ['test', 'apple', 'cars', 'dog']
data = ['cat', 'list', 'text','code']
我想得到以下结果。
test cat
apple list
cars text
dog code
我用以下代码做到了这一点:
for x, y in zip(info, data):
print('{0:18} {1:}'.format(x,y))
它有效,但也许有比我更好的选择/方式?
解决方案
有很多包可以以表格形式打印内容。我建议上去tabulate
from tabulate import tabulate
t = tabulate(zip(info, data), tablefmt="plain")
print(t)
输出
test cat
apple list
cars text
dog code
推荐阅读
- payara - 无法启动 Payara 域
- javascript - 认证通过后输入新的 React 组件
- c++ - 高效的 Graph 数据结构,在 C++ 中支持非常快速的节点和边删除
- java - 构建失败的 Android Room 和 EventBus
- python - 在 Django Rest 框架中为图像返回完整的图像 URL
- r - mlogit 和 clusterSEs - 数据框中的错误
- reactjs - Redux / RTK:为一片创建增强器?
- python - win32com 打开Word
- flutter - 在 Flutter 应用中的 Google 地图顶部添加和动态更改位置小部件的位置
- laravel - Laravel Passport 为每个设备 ID 创建多个访问令牌