November 20th, 2012, 08:58 PM
Here's an example.
A doctest providing supporting evidence that
the function might be correct.
>>> a.count('f') == count(a,'f')
# longer, but still probably shorter than your version, that is, if you bothered to write a solution
occurrences = 0
for obj in L:
occurrences += obj == o
# short form
return sum(obj == o for obj in L)
[/code] are essential for python code!