python 嵌套字典quevalues值_如何根据python中的键值计算字典的频率?

您可以使用dict comprehension获得一个以短语为键、以值为计数的dict。

d = {('The brown fox',): [0], ('the race',): [0], ('Apple',): [1], ('a company Apple',): [1], ('iphone',): [1], ('Paris',): [2], ('Delhi',): [2], ('London',): [2], ('world cities',): [2], ('home',): [3, 4], ('order delivery food',): [3], ('simple voice command',): [3], ('dinner',): [3], ('a long day',): [3], ('work',): [3], ('teams',): [4], ('goal home',): [4], ('fox world',): [5], ('a world class company',): [5], ('A geyser heating system',): [6], ('a lot',): [7], ('the book Python',): [7], ('an amazing language',): [7], ('i',): [8], ('a good boy',): [8], ('Team Performance',): [9], ('Revolv central automation device',): [10], ('the switch way',): [11], ('play children',): [12]}

frequency = {k[0]: len(v) for k, v in d.items()}

print(frequency)

# {'The brown fox': 1, 'the race': 1, 'Apple': 1, 'a company Apple': 1, 'iphone': 1, 'Paris': 1, 'Delhi': 1, 'London': 1, 'world cities': 1, 'home': 2, 'order delivery food': 1, 'simple voice command': 1, 'dinner': 1, 'a long day': 1, 'work': 1, 'teams': 1, 'goal home': 1, 'fox world': 1, 'a world class company': 1, 'A geyser heating system': 1, 'a lot': 1, 'the book Python': 1, 'an amazing language': 1, 'i': 1, 'a good boy': 1, 'Team Performance': 1, 'Revolv central automation device': 1, 'the switch way': 1, 'play children': 1}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值