我希望能够为 python 中的内置计数编写替代代码:此代码有效
def count(element,seq):
"""Counts how often an element occurs
...in a sequence"""
mycount = seq.count(element)
return mycount
但我想把它写在一个 for 循环中(或其他方式?),我已经做到了这一点:
def count(element,seq):
"""Counts how often an element occurs
...in a sequence"""
for i in seq:
if element == seq:
print i
我不确定如何将重新出现的元素作为整数返回。任何帮助表示赞赏!