11. count


#1

I just wanted to ask, is this code correct for complete task?

It's look so simple and takes aboute 1 minute, that never happens in "Practice makes perfect" section.

Summary

def count(sequence, item):
    return sequence.count(item)

#2

yes, its correct. The exercise advises against using this function/method, but its valid. But i think you will learn more from writing your own algorithm.


#3
code

def count(sequence, item):
    word = ""
    number = 0
    for words in sequence:
        if words == item:
            number += 1
    return number

Looks like that's right.


#4

yes, except this line:

word = ""

doesn't do anything, you could remove it


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.