我正在尝试使用一个简单的字典来替换文本文件的每一行上的值与它们各自的字典值,但是在字典的第一行得到"无法分配给操作符错误".以下是我到目前为止的情况......
#!/usr/bin/python
import sys
funcat-cog = {'Translation, ribosomal structure and biogenesis': 'J',
'RNA processing and modification': 'A',
'Transcription': 'K',
'Replication, recombination and repair': 'L',
'Chromatin structure and dynamis': 'B',
'Cell cycle control, cell division, chromosome partitioning': 'D',
'Defense mechanisms': 'V',
'Signal transduction mechanisms': 'T',
'Cell wall/membrane/envelope biogensis': 'M',
'Cell motility': 'N',
'Intracellular trafficking and secretion': 'U',
'Posttranslational modification, protein turnover, chaperones': 'O',
'Energy production and conversion': 'C',
'Carbohydrate transport and metabolism': 'G',
'Amino acid transport and metabolism': 'E',
'Nucleotide trnasport …Run Code Online (Sandbox Code Playgroud) 这很可能以前曾被问过,但我似乎无法找到一个直接的解决方案.假设我在列表中有一堆数字,如:
1234
2233
3232
1234
Run Code Online (Sandbox Code Playgroud)
我需要找到一种方法来使用脚本打印列表中项目的频率总和,如下所示:
1234 2
2233 1
3232 1
Run Code Online (Sandbox Code Playgroud)
有人可以为我阐明这一点吗?
谢谢