Is it possible to convert the following loop:
c = 0
for a in find:
c += 1
return c
Where find is a list like [a,b,c,d] to a function that uses recursion without using external libraries?
def count(ls):
if not ls: # empty
return 0
return count(ls[1:]) + 1
Use it like this:
>>> find = [a, b, c, d]
>>> count(find)
4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With