python - 我试图将三个不同大小的数组打印到表格中
问题描述
a = [1, 2, 3]
b = [a, b, c, d]
c = ["why", "cant", "i", "make", "this", "work"]
期望的输出:
a b c
1 a why
2 b cant
3 c I
d make
this
work
解决方案
你可以参考这段代码。
a = [1, 2, 3]
b = ['a', 'b', 'c', 'd']
c = ["why", "cant", "i", "make", "this", "work"]
def get_safenode(l, i):
if i<len(l):
an=l[i]
else:
an=''
return str(an)
maxlen = max(len(a), len(b), len(c))
print('%3s %3s %-5s' % ('a','b','c'))
for i in range(maxlen):
an = get_safenode(a, i)
bn = get_safenode(b, i)
cn = get_safenode(c, i)
print('%3s %3s %-5s'%(an, bn, cn))
输出是这样的。
a b c
1 a why
2 b cant
3 c i
d make
this
work
推荐阅读
- mysql - 我无法在 nodejs 中发布填充 mysql createconnection 的帖子
- google-apps-script - 从库中的函数运行时出现“ReferenceError:未定义 Jdbc”
- c++ - 编译器警告:执行到达返回值函数的末尾而不返回值
- javascript - 是否可以在组件中获取分配的引用名称?Vue.js
- java - jsp页面中的modelAttribute在非输入字段上返回null
- bash - 如何将 `find` 输出作为 bash 的参数?
- matlab - 我怎样才能摆脱 MATLAB 中的这个错误?
- delphi - Delphi BPL 无法动态加载 64 位包
- objective-c - 禁用按钮循环(NStimer 或 MouseMove)XCode Objective-C MacOS
- c - Zentyal 代理 6.1 的问题和嵌入式应用程序中的连接请求