输入数组
python输入n*n的矩阵
n = int(input())
rect = []
for i in range(n):
rect.append(list(map(int, input().split())))
python输入m*n的矩阵
dp = [[0 for i in range(n+1)]for i in range(m+1)]
返回列表中最小值其所在位置
t = [4,1,8,3]
t.index(min(t)) # 返回最小值
去除列表中重复元素
法一:
l = [1,2,3,4,4]
l2 = list(set(l))
法二:
l = [1,2,3,4,4]
l2 = list()
for i in l:
if i not in l2:
l2.append(i)
统计列表中元素出现次数
a = [1, 2, 3, 1, 1, 2]
dict = {}
for key in a:
dict[key] = dict.get(key, 0) + 1