Notes learning python "python programming quick start - let automate the tedious work" of the three

Problem three:
interesting table

grid = [['.', '.', '.', '.', '.', '.'],
		['.', 'O', 'O', '.', '.', '.'],
		['O', 'O', 'O', 'O', '.', '.'],
		['O', 'O', 'O', 'O', 'O', '.'],
		['.', 'O', 'O', 'O', 'O', 'O'],
		['O', 'O', 'O', 'O', 'O', '.'],
		['O', 'O', 'O', 'O', '.', '.'],
		['.', 'O', 'O', '.', '.', '.'],
		['.', '.', '.', '.', '.', '.']]
需要打印出如下效果:
result=[('.', '.', 'O', 'O', '.', 'O', 'O', '.', '.'),
		('.', 'O', 'O', 'O', 'O', 'O', 'O', 'O', '.'),
		('.', 'O', 'O', 'O', 'O', 'O', 'O', 'O', '.'),
		('.', '.', 'O', 'O', 'O', 'O', 'O', '.', '.'),
		('.', '.', '.', 'O', 'O', 'O', '.', '.', '.'),
		('.', '.', '.', '.', 'O', '.', '.', '.', '.'),
]
'''结果是把grid列表顺时针旋转90度,'''
def reseau(lists):#循环取值
	rows=len(lists)#有多少行.
	min_list=[len(lists[i]) for i in range(rows)]
	column=min(min_list)#算出最短列数
	for y in range(column):
		for x in range(rows):
			print(lists[x][y],end='')
		print()#换行
**#更加简单的方法用zip()函数,一行解决
new_list=[i for i in zip(*grid)]
pprint.pprint(new_list)**#导入pprint模块
Published 23 original articles · won praise 5 · Views 391

Guess you like

Origin blog.csdn.net/weixin_43287121/article/details/104479055