f count(sequence,item):
    co = 0
    for i in sequence:
        if i == item:
            co = co + 1
        print co
        return co


i tried removing range, sequence[i] == item one by one.. nothing is working.
simply showing error of returning 0 not 1


Your return is inside the for-in loop. So the first time the code reaches return, it ends the whole for-in loop. To solve this, you just need to remove the indentation in front of the return.


awesome... thank you so much


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