Python - 列表中的列表列表列表 [英] Python - write list list of lists in columns

查看:130
本文介绍了Python - 列表中的列表列表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表的列表有不同数量的元素(int)。

I have a list of lists with a various number of elements (int). I want to print/write it, but in columns rather than in rows.

例如:

l = [[1,2,3],[4,5],[6,7,8,9],[0]]

结果:

1 4 6 0
2 5 7 .
3 . 8 .
. . 9 .


推荐答案

最简单的方法是使用 itertools.izip_longest()

for x in itertools.izip_longest(*l, fillvalue="."):
    print " ".join(str(i) for i in x)

这篇关于Python - 列表中的列表列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆