python 对二维列表进行按行读取和按列读取

上代码!!!

# 创建一个二维列表
listA = [ 
["wo","hen","ni"], 
["ai","si","ni"], 
["ni","ni","ni"] ]
 
# 按照行来访问
for row in listA:
	print(row)
 
# 按照列来访问
for i in range(3):
	COLUMN = [column[i] for column in listA]
	print(COLUMN)

按行访问输出结果:

['wo', 'hen', 'ni']
['ai', 'si', 'ni']
['ni', 'ni', 'ni']

按列访问输出结果:

['wo', 'ai', 'ni']
['hen', 'si', 'ni']
['ni', 'ni', 'ni']

以上是我的学习笔记,如果能帮到您, 卑微求个小赞,谢谢您的观看!!!

你可能感兴趣的:(Python,python,列表,经验分享)