[Tutor] Understanding error in recursive function

Tom Maher tomjmaher4 at gmail.com
Fri Apr 8 16:48:21 EDT 2016


Hi,

As a test I am trying to write a function that returns the sum of values
attached to one key in a dictionary. I am wondering why the code that I
wrote is returning:
"maximum recursion depth exceeded "
Here is the code:

animals = { 'a': ['aardvark'], 'b': ['baboon'], 'c': ['coati']}

x = animals['a']

def howMany(aDict):

      count = 0

      for value in howMany(aDict):

           count += 1

      return count

howMany(x)


Just wondering why I would be getting that error.


Thanks


More information about the Tutor mailing list