Count; this code works; yet unallocated error message


Oops, try again. Your code looks a bit off--it threw a "'list' object has no attribute 'split'" error. Check the Hint if you need help!

Code functions, also when tested in Atom. Yet Code Academy won't approve
What is the reason for this error message. How can I solve this problem

def count(sequence, item):
    print sequence
    split_list = sequence.split()
    print split_list
    count = 0
    for i in range(len(split_list)):
        if split_list[i] == item:
            count += 1
            print "Get on with it"
    return count
    print count
sequence = raw_input("items seperated by spaces: ")
item = raw_input("Which item should be counted? ")
print count(sequence, item)


that is because in your case sequence is a string, while the exercise expects its to be a list.

when you already have a list, you don't have to split


Thank you very much.


A post was split to a new topic: Count


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