here is sample for my_count(list,o bj)
Code:
def my_count(my_list,my_obj):
""" This function is equivalent to the built-in list function "count". """
if not(my_obj in my_list) :
return 0
else:
count_int=0
for current_obj in my_list:
if current_obj==my_obj:
count_int=count_int+1
return count_int
def main():
test_list=['dog',1,'cat',1,3,'dog',4,['dog',3],1]
# Test my_count and compare it to built in list function count
# Test 1
print ("Built-in count function returned : ",test_list.count('dog'))
print ("my_count function returned : ", my_count(test_list,'dog'))
# Test 2
print ("Built-in count function returned : ",test_list.count(1))
print ("my_count function returned : ",my_count(test_list,1))
# Test 3
print ("Built-in count function returned : ",test_list.count('bird'))
print ("my_count function returned : ",my_count(test_list,'bird'))
if __name__ == "__main__": # if the function is the main function then call the main()
main()
Comment