• 简易检索系统


    #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 info
    
    def printFindList(list,conn='	'):
        connprintstr=[]
        for x in list:
            pos=x.find(query)
            if pos!=-1:
                connprintstr.append(x[:pos]+'33[32;1m%s33[0m'%query+x[pos+len(query):])
            else:
                connprintstr.append(x)
        return conn.join(connprintstr)
    
    def colorPrint(query,color):
        if color=='red':
            return '33[31;1m%s33[0m'%query
        if color=='green':
            return '33[32;1m%s33[0m'%query
    
    info=getDictFromFile('D://info.txt')
    
    while True:
        query=raw_input('33[32;1m请输入关键字:33[0m').strip()
        findcount=0
        if len(query)<3:
            print('你需要输入的关键字至少大于3个字符!')
            continue
        for k,v in info.items():
            index=k.find(query)
            if index!=-1:
                findcount+=1
                print(k[:index]+colorPrint(query,color='greed')+k[index+len(query):],v)
            else:
                if ''.join(v).find(query)!=-1:
                    findcount+=1
                    print(k+'	'+printFindList(info[k]))
        print('找到'+colorPrint(findcount,color='red')+'处关键字!')
    
    
    '''
    -----------------------------
    请输入关键字:system
    stu1103	lixaonong	43mnfj@126.com	www.google.com	461	system
    stu1102	zhangsanfeng	qrjffd@bi.com	www.gl.com	24415	system
    stu1101	yangwubing	8131415@qq.com	www.baidu.com	14545166	system
    stu1105	lixaonong	43mnfj@126.com	www.google.system	system	system
    stu1104	lixaonong	43mnfj@126.com	www.google.com	461	system
    -----------------------------
    '''
    

      

  • 相关阅读:
    watch监听不到data数据
    滑块验证码 纯js
    position: fixed居中
    Vue插件之缺口滑块验证码 适合于手机和pc(插件vuemonoplastyslideverify)
    Vue之滑动验证码 适合于手机和pc JcRange(可分辨系统)
    Bus
    Table表中添加下拉框
    容器docker网络解析
    jstack定位java程序CPU使用高问题
    <摘>C#,MFC,Win32——实现系统级热键
  • 原文地址:https://www.cnblogs.com/similarface/p/5399934.html
Copyright © 2020-2023  润新知