Recursion: Call the function itself in a function
The maximum depth to be fixed to recursion
Import Sysprint (Sys.setrecursionlimit (100000))
Recursive implementation of level three menus
1menu = {2 'Beijing': {3 'Haidian': {4 'Five crossing': {5 'Soho': {},6 'NetEase': {},7 'Google': {}8 },9 'Zhongguancun': {Ten 'Iqiyi Art': {}, One 'Autohome': {}, A 'Youku': {}, - }, - 'on the ground': { the 'Baidu': {}, - }, - }, - 'changping': { + 'Shahe': { - 'old boy': {}, + 'Beihang University': {}, A }, at 'Tin Tong Court': {}, - 'Huilongguan': {}, - }, - 'Chaoyang': {}, - 'Dongcheng': {}, - }, in 'Shanghai': { - 'Minhang': { to "People's square": { + 'Fried Chicken Shop': {} - } the }, * 'Zhabei': { $ 'Train Warfare': {Panax Notoginseng 'Ctrip': {} - } the }, + 'Pudong': {}, A }, the 'Shandong': {}, + } - $ defThree (DIC): $ forKeyinchDIC: - Print(Key) -K = input ('>>>>>>>') the ifKinchDIC: - three (dic[k])WuyiThree (DIC)
Detailed Examples
Two-point lookup algorithm:
L = [2,3,5,10,15,16,18,22,26]def Find (L,aim,start,end): mid = (end+start)//2 if L[mid] > aim: #中间值大于目标值 , left search end = Mid #头部不变, return Find (l,aim,start,end) elif L[mid] < aim: start= mid return Find (L,aim,start,end) else: return Midprint (Find (L,15,start=0,end=len (L)-1))
Recursive and binary algorithms