【问题标题】:Why 'dict(Count(list)) does not work in python for windows?为什么 'dict(Count(list)) 在 windows 的 python 中不起作用?
【发布时间】:2020-07-03 15:37:39
【问题描述】:
def codon_usage(seq, aminoacid):
    """Provides the frequency of each codon encoding a given aminoacid in a DNA sequence"""
    tmpList = []
    for i in range(0, len(seq) - 2, 3):
        if DNA_Codons[seq[i:i + 3]] == aminoacid:
                tmpList.append(seq[i:i + 3])

    freqDict = **dict(Counter**(tmpList))
    totalWight = sum(freqDict.values())
    for seq in freqDict:
        freqDict[seq] = round(freqDict[seq] / totalWight, 2)
    return freqDict

您好,我正在尝试此代码,但无法使其运行。 'dict(Counter(list)' 应该检索一个字典,其中键是我的序列,值是该键出现的次数。但是,错误消息是未定义 'count' 变量。这段代码来自使用 Linux 的视频 有人可以帮我吗?

【问题讨论】:

  • Counter 在任何地方定义。这不是 Windows 的事情。很可能,这意味着来自collections 模块
  • 你没事!谢谢

标签: python windows bioinformatics


【解决方案1】:

你需要导入Counter:

from collections import Counter

【讨论】:

  • 我能再问你一个问题吗?我在哪里可以找到有关这些收藏的信息?我一直在字典和列表部分的 Python 纪录片中查找,但什么也没找到
  • @Christ14n97 我想这就是你要找的东西:docs.python.org/3/library/collections.html
  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2019-03-17
  • 2017-11-17
  • 2020-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-02
相关资源
最近更新 更多