摘要:
读取文件,且不打印某一行。 f = open("myfile",'r',encoding="utf-8") for index,line in enumerate(f.readlines()): #此写法只适合读取小文件 if index==2: #第3行不打印 continue print(lin 阅读全文
摘要:
def bubble_sort(li): for i in range(len(li)-1): exchange = False for j in range(len(li)-i-1): if li[j] > li[j+1]: li[j], li[j+1] = li[j+1], li[j] exch 阅读全文
摘要:
1.二分查找(折半查找) def binary_search(li,val): left = 0 right = len(li)-1 # 表示索引 while left <= right: mid = int((left + right)/2) if val == li[mid]: return m 阅读全文