
November 20th, 2012, 07:58 PM
|
 |
Contributing User
|
|
|
|
Here's an example.
Code:
def count(L,o):
'''
A doctest providing supporting evidence that
the function might be correct.
>>> a='forty-five'
>>> a.count('f') == count(a,'f')
True
'''
# 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
return occurrences
# short form
return sum(obj == o for obj in L)
__________________
[code] Code tags[/code] are essential for python code!
|