栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python test

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号