al之查找

查找最小值

1
2
3
4
5
6
7
8
def index_of_min(lyst):
minIndex = 0
currentIndex = 1
while currentIndex < len(lyst):
if lyst[currentIndex] < lyst[minIndex]:
minIndex = currentIndex
currentIndex += 1
return minIndex

python当中的min函数返回列表中的最小的项

顺序搜索一个列表

list类名为 __contains__ 的方法实现了in的运算符操作

有序列表中各种 二分查找

的变种 一定需要自己多次手写

比较数据项

  • __eq__
  • __lt__
  • __gt__
  • __le__
  • __ge__