用Python方式打印2D列表的方法-Python [英] Pythonic way to print 2D list -- Python
本文介绍了用Python方式打印2D列表的方法-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以这种方式获得了二维字符列表:
I have a 2D list of characters in this fashion:
a = [['1','2','3'],
['4','5','6'],
['7','8','9']]
将列表作为一个整体打印出来的最Python方式是什么? IE.没有逗号或括号:
What's the most pythonic way to print the list as a whole block? I.e. no commas or brackets:
123
456
789
推荐答案
有很多方法.可能是str.join
s的映射的str.join
:
There are a lot of ways. Probably a str.join
of a mapping of str.join
s:
>>> a = [['1','2','3'],
... ['4','5','6'],
... ['7','8','9']]
>>> print('\n'.join(map(''.join, a)))
123
456
789
>>>
这篇关于用Python方式打印2D列表的方法-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文