Count


#1



My count function works as long as the item isn't another list but when it is another list, it fails. How can you edit this so that it works if the item is another list?


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


#2

works fine for list as well:

def count(sequence, item):
    times = 0
    for i in sequence:
        if item == i:
            times += 1
    return times
    
print count([[4,5]],[4,5])

What cases are your thinking your function can't currently handle?


#3

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