Python 从列表创建板
比如说,我有一个列表['0-0-0','10-1-2','15-2-3','6-4-5']。我想定义一个函数来创建一个电路板,使其显示如下:Python 从列表创建板,python,list,Python,List,比如说,我有一个列表['0-0-0','10-1-2','15-2-3','6-4-5']。我想定义一个函数来创建一个电路板,使其显示如下: Diamond Sword Enemie 0 0 0 10 1 2 15 2 3 6 4 5 这是我的代码: def create_lists_board(listStrings): lists_board=[] biome_biome=["Biome#",0,1
Diamond Sword Enemie
0 0 0
10 1 2
15 2 3
6 4 5
这是我的代码:
def create_lists_board(listStrings):
lists_board=[]
biome_biome=["Biome#",0,1,2,3,4,5,6,7]
biome_diam=["Diam"]
biome_sword=["Sword"]
biome_enemy=["Enemy"]
for i in listStrings:
n=i.split("-")
biome_diam.append(int(n[0]))
biome_sword.append(int(n[1]))
biome_enemy.append(int(n[2]))
lists_board=biome_biome+biome_diam+biome_sword+biome_enemy
return lists_board
这是错误的,我不知道为什么您可以在这里使用字符串格式:
lis = "Diamond Sword Enemie".split()
lis1 = ['0-0-0','10-1-2','15-2-3','6-4-5']
print "{:10} {:^8} {:>10}".format(*lis)
for x in lis1:
print "{:10} {:^8} {:>10}".format(*x.split('-'))
输出:
Diamond Sword Enemie
0 0 0
10 1 2
15 2 3
6 4 5
怎么了?你有错误吗?
def create_lists_board(listStrings):
print "Diamond Sword Enemy"
for i in listStrings:
n = i.split("-")
print "%s \t %s \t %s"%(str(n[0]), str(n[1]), str(n[2]))
create_lists_board(['0-0-0','10-1-2','15-2-3','6-4-5'])