start,end=0,len(array)-1
while start<=end:
mid=(start+end)//2
if a[mid][0]==value:
return mid
咐局 elif a[mid][0]>value:
end=mid-1
else:
start=mid+1
return None
if __name__=="__main__"袜差:
array=[ ['201801', '张三'], ['201822', 'Andy Lee'], ... ,['20189X','Austin Hu'] ],省略数据请自行补充
index=find(array,studentno)
告简皮 if index is None:
print("未找到学号:%s"%studentno)
else:print(array[index])
#!bin/python #-*- encoding: utf-8 -*- def counter(path, find, punctuation): infile = open(path, "r") lenth = len(find) count = [] for i in range(lenth): count.append(0) dat = infile.readline().strip("\n") while dat != '': dat = dat.split() for elemt in dat: elemt = elemt.strip(punctuation) #去除标点符号粗斗 if elemt in find: i = find.index(elemt) count[i] += 1 dat = infile.readline().strip("\n") infile.close() for i in range(lenth): print "%s:%d次" % (find[i],count[i]) if __name__ == "__main__": path = "PATH" find = ["hello", "袜凳手hi", "world"] punctuation = ''告嫌',.'":!?''' counter(path, find, punctuation)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)