184k views
0 votes
write a function, count() that accepts a list and a value to search for in the list, returning the number of times it finds that value in the list.

1 Answer

0 votes

Answer:

Here is one possible implementation of the count() function:

def count(lst, value):

count = 0

for elem in lst:

if elem == value:

count += 1

return count

Here is an example of how you could use this function:

myList = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2]

numOnes = count(myList, 1)

print(numOnes) # outputs 3

User Cmoetzing
by
4.6k points