Listl.pop(i)弹出第i个元素forindex,numinenumerate(nums)l[::-1]l.count(x)listcomprehension:newlist=[xifx!="banana"else"orange"forxinfruits]Sort1:min(l,key=lambdax:abs(target-x))Sort2:SortArraybyIncreasingFrequency:deffrequencySort(self,A):count=collections.Counter(A)returnsorted(A,key=lambdax:(count[x],-x))Sort3:sentences是一个句子列表,times是一个数字列表,表示该句子出现了多少次。按时间排序句子,然后按字母排序。#https://stackoverflow.com/questions/6618515/sorting-list-based-on-values-from-another-list#https://stackoverflow.com/questions/16193578/how-do-i-perform-secondary-sorting-in-python#https://stackoverflow.com/questions/4659524/how-to-sort-a-list-by-length-of-string-followed-by-alphabetical-orderself.history=[x对于_,xinsorted(zip(times,sentences),key=lambdapair:(-pair[0],pair[1]))]orself.times_dict=dict(zip(sentences,times))self.history=sorted(sentences,key=lambdax:(-self.times_dict[x],x))Dictionary导入集合,collections.defaultdict(int),collections.defaultdict(list)defconstant_factory(value):returnlambda:valued=defaultdict(constant_factory(''))导入集合,counts=collections.Counter(nums)dictionary.get(keyname,optional_value_if_key_not_exist_default_None)dict(zip(sentences,times)))Dictindict:FieldGoalsPerGame[Pdict['KobeBrayant']][Sdict['2009']]Setset1&set2LinkedListhead.nextTreeifnodenode.val,node.left,node.rightBST二叉搜索树:left40stats[Filter]FilterandFilter2:errorFilter&Filter2:workstats[Filter&Filter2]stats.iat[0,1]:forintegerlocationstats.at[0,'BirthRate']:atforlabelsPlotplt.plot(Salary[0],c='Black',ls='--',market='s',ms=7,label=Players[0])plt.plot(Salary[1],c='Red',ls='--',market='o',ms=7,label=Players[1])plt.plot(loc='upperleft',bbox_to_anchor=(1,1))plt.xticks(list(range(0,10)),季节,旋转='vertical')plt.show()ClassTemplate:类AutocompleteSystem:def__init__(self,a:List[str],b:List[int]):self.a=a...definput(self,c:str)->List[str]:...returndSQL%macroPulldata(mth,dte);ProcSQL;CONNECT使用db2;CREATETABLEFULL_XAA_&mth._1ASSELECT*FROMCONNECTIONTOdb2(SELECT*FROMDW.RLTN_DIM)otherfloat('inf')mod(value,2)ord('A')产生常见的解题技巧遍历过程中使用hashmap存储避免重复遍历2指针二分法,3个指针(left,pivot,right)动态规划,存储上一轮的结果,遍历过程中不断更新变量DFSDepthFirstSearchBFSBreadthFirstSearchbucketsort/countingsortGreedy:Greedyalgorithm(贪心算法)也称为贪心算法,是在每一步选择中取当前状态下最好的或最优的(即最有利的)选择,因此,希望结果是最好的或最优的算法.贪心算法与动态规划的不同之处在于,它为每个子问题的解决方案做出选择并且不能回退。动态规划会保存之前的计算结果,并根据之前的结果选择当前的,具有回滚功能。