Python 字典计数

标签 python list python-2.7 python-3.x

问题:

您好,我是 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 上搜索图书馆。有很多不错的。

关于Python 字典计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33510452/

相关文章:

python - PDB 如何在退出时中断?

python - Tensorflow 在多数投票上表现缓慢

java - 如何从列表中返回数组 [Java]

algorithm - 如何对不相交的子列表进行排序?

python - 比较两个包含 NaN 的矩阵并屏蔽两个矩阵中至少其中一个在 Python 中包含 NaN 的元素值

python - 将 Pandas 日期列转换为经过的秒数

python re 模块替换文本文件中的二进制数据?

python - 如何将二维列表写入文件

python - 如何在 z3 python API 中使用 Implies 和 if bool 命令

python - 处理Python中的记录器错误