Skip to main content
 首页 » 编程设计

Python 字典计数

2025年05月04日12think

问题:

您好,我是 Python 的新手,因此需要一些帮助。我有多条输入线。我正在寻找一种方法来从多个列表中获取每个单词,然后将它们相加以获得多个列表中该单词的每个实例的总数。我将非常感谢任何指导。

请您参考如下方法:

编辑:

"""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 操纵基因组 Material 的方法,您可以在 pypi.python.org 上搜索图书馆。有很多不错的。