算法运用
字典查询键值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
for k in d.keys(): print(k) for v in d.values(): print(v) for a,b in d.items(): print(a,b)
递归
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
def Number(at): if at==0: return 0 elif at==1: return 1 else: return Number(at-2)+Number(at-1) num=input("请输入:") print(Number(int(num)))
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Number: def auto1(self,at): if at==0: return 0 elif at==1: return 1 return self.auto1(at-2)+self.auto1(at-1) # return at*self.auto1(at-1) at1=Number() print(at1.auto1(int(input())))
快排排序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
def Kuaipai(alist): if len(alist)<2: return alist tom=alist[0] left=[x for x in alist[1:] if x<=tom] right=[i for i in alist[1:] if i>tom] return Kuaipai(left)+[tom]+Kuaipai(right) li=[1,5,7,9,3,8,6] print(Kuaipai(li))
冒泡排序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
def Maopao(alist): for i in range(len(alist)-1): for j in range(len(alist)-i-1): if alist[j]>alist[j+1]: alist[j],alist[j+1]=alist[j+1],alist[j] li=[1,5,7,9,3,6,4] Maopao(li) print(li)
二分查找
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
def Erfen(alist,a): num=0 high=len(alist)-1 while num<=high: mid=(num+high)//2 if alist[mid]==a: return mid elif alist[mid]<a: num=mid+1 else: high=mid-1 return False alista=[1,2,3,4,5,6,7,8] aa=6 print(Erfen(alista,aa))