#coding: utf-8__author__ = ' HDFs ' def getdictfromfile (file): info={} with open (file, ' R ') as F:for line in F: Stuid,name,qq,www,score,role=[x.strip () for X in Line.split (")] Info[stuid]=[name,qq,www,score,role ] Return infodef printfindlist (list,conn= ' \ t '): connprintstr=[] for x in List:pos=x.find (query) if Pos!=-1:connprintstr.append (x[:p os]+ ' \033[32;1m%s\033[0m '%query+x[pos+len (query):]) else:c Onnprintstr.append (x) return Conn.join (CONNPRINTSTR) def colorprint (query,color): If color== ' Red ': Return ' \03 3[31;1m%s\033[0m '%query if color== ' green ': Return ' \033[32;1m%s\033[0m '%queryinfo=getdictfromfile (' D://info.txt ' While True:query=raw_input (' \033[32;1m Please enter the keyword: \033[0m '). Strip () findcount=0 if Len (query) <3:print (' You need to The keyword you want to enter is at least 3 characters long! ') continue for k,v in Info.items (): index=k.find (query) if index!=-1:findcount+=1Print (K[:index]+colorprint (query,color= ' greed ') +k[index+len (query):],v) else:if ". Join (v). Find (query)! =-1:findcount+=1 print (k + ' \ t ' +printfindlist (INFO[K)) print (' Find ' +colorprint (Findcount,co Lor= ' red ') + ' keywords! '-----------------------------Please enter the keyword: systemstu1103lixaonong[email protected] Www.google.com461systemstu1102zhangsanfeng[email protected]www.gl.com24415systemstu1101yangwubing[email protected]www.baidu.com14545166systemstu1105lixaonong[email protected] Www.google.systemsystemsystemstu1104lixaonong[email protected] Www.google.com461system-----------------------------""
Simple Retrieval System