如何获取嵌套列表并将其显示在curses中?

时间:2017-02-09 18:00:16

标签: python python-3.x curses

我想要一个像这样的列表

mylist = [['_','X','_'],['X','_','_'],['X','_','_']]

并显示如下:

_ X _
X _ _
X _ _

我会使用2个嵌套循环并构建一个字符串吗?

mystring=''
for line in mylist:
   for char in line:
       mystring += char + ' '
   mystring += '\n'
screen.addstr(mystring,0,0)

2 个答案:

答案 0 :(得分:1)

使用str.join

mylist = [['_','X','_'],['X','_','_'],['X','_','_']]

mystring = '\n'.join(' '.join(sublist) for sublist in mylist)

screen.addstr(mystring,0,0)

答案 1 :(得分:0)

您可以使用str.join执行此操作:

for i in mylist :
    print ''.join(i)

如果您想在字符之间留出空格,请用空格''替换' '