Python常用函数
来源:互联网 发布:意大利 世界杯 知乎 编辑:程序博客网 时间:2024/06/07 04:11
常用的字符串方法
列表函数
列表方法
集合运算及运算符
字典
附录:
def find_two_smallest(L): '''Return a tuple of the indices of the two smallest values in list L''' if L[0] < L[1]: min1,min2 = 0,1 else: min1,min2 = 1,0 for n in range(2,len(L)): if L[n] < L[min1]: min2 = min1 min1 = n elif L[n] < L[min2]: min2 = n return (min1,min2)def linear_search(L,v): '''Return the index of the first occurrence of v in list L, or return len if v is not in L''' for i in range(len(L)): if L[i] == v: return i return len(L)def selection_sort(L): '''Reorder the values in L from smallest to largest.''' i = 0 while i != len(L): smallest = find_min(L, i) L[i],L[smallest] = L[smallest],L[i] i += 1def find_min(L,b): '''Return the index of the smallest value in L[b:].''' smallest = b # The index of the smallest so far. i = b + 1 while i != len(L): if L[i] < L[smallest]: smallest = i i += 1 return smallestdef insertion_sort(L): '''Reorder the values in L from smallest to largest.''' i = 0 while i != len(L): insert(L, i) i += 1def insert(L, b): '''Insert L[b] where it belongs in L[0:b+1]; L[0:b-1] must already be sorted''' i = b while i != 0 and L[i-1] > L[b]: i -= 1 value = L[b] del L[b] L.insert(i, value)
0 0
- python常用常用函数
- python常用常用函数
- python常用常用函数
- python常用常用函数
- Python常用函数
- Python常用内置函数
- Python常用内置函数
- PYTHON字典常用函数
- PYTHON字符串常用函数
- PYTHON列表常用函数
- Python常用函数
- python 常用函数举例
- python常用函数
- python 常用函数笔记
- python调试常用函数
- python最常用函数
- python最常用函数
- Python常用函数
- 新浪微博note
- Path Sum II--LeetCode
- 关键字final
- C++ typedef 类型前置声明
- 黑马程序员——java基础——两个排序,一个查找
- Python常用函数
- 【翻译自mos文章】闪回区和flashback database
- 第五周阅读程序二
- linux中的进程和线程
- ZOJ 1006
- 算法——C++——插入排序——
- mysql 创建用户与授权
- JAVA编程思想(第4版)对象终结条件,system.gc(),finalize()一部分用法小结
- 【最大流之EdmondsKarp算法】【HDU1532】模板题