Python字典计数 [英] Python dict count

查看:79
本文介绍了Python字典计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我是Python的新手,所以正在寻求帮助.我有多条输入线.我正在寻找一种方法来从多个列表中提取每个单词,然后将它们相加以获得多个列表中该单词在每个实例上的总计数.我将非常感谢您的指导.

Hi I'm new to Python so looking for some help. I have multiple input lines. I'm looking for a way to take every single word from multiple list and then add them up to get the total count on each instance for that word in multiple List. I will really appreciate any guidance.

推荐答案

"""I need a count of the word given by key(s) in multiple lists at the given index. So what I need is
>>> count(["a", "b", "c"], ["c", "b", "a"])
{"a": [1,0,1], "b": [0,2,0], "c": [1,0,1]}":
"""

我希望这是正确的:

def count (*args):
    l = len(args[0])
    end = {}
    for lst in args:
        y = 0
        for x in lst:

            end.setdefault(x, l*[0])
            end[x][y] += 1
            y += 1
    return end

如果您需要一种从RNA/DNA处理基因组材料的方法,则可以在pypi.python.org上搜索库.有很多不错的.

If you need a way to manipulate genome material from RNA/DNA you can search for libraries on pypi.python.org. There are plenty good ones.

这篇关于Python字典计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆