对于3*4的列表
A = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 8, 7, 6]]
取出某行某列的元素
print(A[2][1]) # 8
取出每一行的元素
print(A[1]) # [5, 6, 7, 8]
取出每一列的元素
# 第一种
for i in range(4):
print([row[i] for row in A])
# 输出
[1, 5, 9]
[2, 6, 8]
[3, 7, 7]
[4, 8, 6]
# 第二种
for col in zip(*A):
print(col)
# 输出
(1, 5, 9)
(2, 6, 8)
(3, 7, 7)
(4, 8, 6)
取出列表符合下列条件的:在同一行的所有元素中最小,在同一列的所有元素中最大
A = [[1, 10, 4, 2],
[9, 3, 8, 7],
[15, 16, 17, 12]]
r = [min(i) for i in A]
c = [max(i) for i in zip(*A)]
print([t for t in r if t in c]) # 12
print(list(set(r) & set(c)) ) # 12
#### or
print(list(set(min(i) for i in A) & set(max(i) for i in zip(*A)))) # 12