• Python test


    #coding:utf-8

    data_list=[
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch0’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU2”],
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU2”],
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU9”],
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU3”],
        [‘ch1’,“ce1”,“lun1”,“TU8”],
        [‘ch1’,“ce1”,“lun1”,“TU1”],
        [‘ch1’,“ce1”,“lun1”,“TU5”],
        [‘ch1’,“ce1”,“lun1”,“TU5”],
    ]

    filer_obj={}

    def probability(data):
        for item in data:
            address=item[-1]  #获取存放的地址
            tu_type=item[0]+item[1]+item[2]
            # print(tu_type,666)
            if address not in filer_obj.keys():#判断当前的tu是否存在于filter_obj的key中,如果没有给一个默认空list
                filer_obj[address]=[]
            # print(filer_obj[address],‘uuuu’)
            if tu_type not in filer_obj[address]: #前三列元素是否在分类中的list中 本意是去重
                filer_obj[address].append(tu_type)
        # print(filer_obj)
        #循环遍历生成的字典,并计算概率
        for key in filer_obj:
            num=len(filer_obj[key])  #当前tu出现的次数
            sum=100  #总数
            print("{}的概率是{}%".format(key,num/sum*100))

    if name==“main”:
        probability(data_list)

  • 相关阅读:
    CAS :80750-24-9(脱硫生物素 NHS 酯)
    Java制作罗盘
    CSS 单位解析
    java通过zookeeper 高可用方式连接hiveserver2
    我的递归从不爆栈
    巴特沃斯、切比雪夫I型、切比雪夫Ⅱ型和椭圆型滤波器的相同和不同之处
    String类的常用方法(Java)
    网络安全(黑客)自学路线
    哨兵模式(sentinel)
    计算机网络第二章习题_物理层
  • 原文地址:https://blog.csdn.net/zyxczyf123/article/details/125500757