11. count


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.


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


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.


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

Looks like that's right.


yes, except this line:

word = ""

doesn't do anything, you could remove it


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