title: Recursive Python function to count occurrences of an element in a list
body: <p>How do I do a recursive function that tells me how many time an element exists in a list. As an example lets say I have the following list ['a','b','c','b','b','d']. How do I do a recursive function that takes 2 arguments. One being the list and the other the element. The function has to return the number of times the element is present in the list.</p>
  
  <p>I tried the following but position gets restarted everytime we go back in the function:</p>
  
  <pre><code>def number_of_repetitions(liste, element):
  
  
      position = 0
      number_of_rep = 0
  
  
      if position == len(liste)-1:
          return number_of_rep
  
      if liste[position] == element:
          position +=1
          return number_of_rep + number_of_repetitions(liste[position], element)
      else:
          position +=1
          return number_of_rep + number_of_repetitions(liste[position], element)
  
  print(number_of_repetitions(['a','b','c','b'],'b'))
  </code></pre>