def count(lst, value):
c = 0
for i in range(lst.size):
if get(lst,i) == value:# get(lst, i) is predefined. It gives me the value at i in lst
c = c + 1
return c
答案 0 :(得分:1)
似乎你想要计算lst
中有多少元素等于value
恕我直言,你可以在一条短线内获得计数,而不是这样做:
lst.count(value)
答案 1 :(得分:0)
这应该成为诀窍:
def recount(lst, value):
if len(lst) == 0:
return 0
if get(lst,0) == value:
return 1 + recount(lst[1:],value)
else:
return recount(lst[1:], value)