#11.Count: is there an incongruence?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

CHECH #11. COUNT

<do not remove the three backticks above>

#2

THIS CODE PASSES SUCCESFULLY, BUT OUTPUT 0 IS WRONG

def count(sequence, item):
    found = 0
    for i in sequence:
        if i == item: 
            found += 1
    return found

print count("one two one thre one", "one")

THIS CODE DOESN’T PASS, BUT RUNS SMOOTHLY ON LICLIPSE AND OUTPUT 3 IS CORRECT

def count(sequence, item):
    found = 0
  
# HERE I SPLIT THE SEQUENCE 
    for i in sequence.split():
        if i == item: 
            found += 1
    return found

print count("one two one thre one", "one")

WHY ?


#3

well, the exercise will test lists on your function, which works in your first example:

def count(sequence, item):
    found = 0
    for i in sequence:
        if i == item: 
            found += 1
    return found

print count(["one", "two", "one", "thre", "one"], "one")

but not in your second. The reason the second code is working in eclipse, is because string does support split, but lists don’t (which is what the exercise throws at your function)


#4

oooops !

I was getting if fast and skipped the detail…

Thank You stetim94 !

I was NOT checking a list within:

print count(“one two one thre one”, “one”)

That’s obvious, now.