iteralbe指的是能够一次返回它的一个成员的对象.iterable主要包括3类: 第一类是所有的序列类型,比如list(列表).str(字符串).tuple(元组). 第二类是一些非序列类型,比如dict(字典).file(文件). 第三类是你定义的任何包含__iter__()或__getitem__()方法的类的对象. sorted(iterable[,cmp,[,key[,reverse=True]]]) 作用:Return a new sorted list from the it
官方文档: sort(*, key=None, reverse=False) This method sorts the list in place, using only < comparisons between items. Exceptions are not suppressed - if any comparison operations fail, the entire sort operation will fail (and the list will likely be le
Python版的快排,使用递归. 1.设置递归终止条件,当元素个数<1时 2.从列表中pop出一个元素pv 3.列表中的剩余值与pv进行对比,大的放入smaller列表,小的放入larger列表 4.返回qs(smaller)+[pv]+qs(larger) 代码如下: def quicksort(array): smaller=[];larger=[] if len(array)<1: return array pv=array.pop() for num in array: if num&