我相信这个问题在这里已经讨论过很多次了,我只是找不到合适的词来找到与这个问题相关的问题。在
这是我的密码。在
def getcopies(listoflists, id_col):
for item in listoflists[1:]:
key = getid(item[id_col])
copies[key] = copies.get(key, 0) + 1
print copies
这是我的输出。在
^{pr2}$这就是我想要的输出。在
{'20302001': 1, '20301001': 1, '20300001': 1, '20303001': 1}
我的代码显然运行缓慢。如何使其更快,如何避免不需要的输出?在
将您的
print copies
放在循环之外,并在启动循环之前初始化它。在找到了!对不起,我应该把我所有的代码都贴出来。问题出在getid()上。我是这样定义的:
当我把它改成:
^{pr2}$一切都开始奏效了。在
只需删除最后一行的缩进。“for item”下面缩进的所有内容都将执行x次,其中x是任何元素中的元素数。在
相关问题 更多 >
编程相关推荐