Count; this code works; yet unallocated error message


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/1?curriculum_id=4f89dab3d788890003000096


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
        else:
            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)


#2

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


#3

Thank you very much.


#4

A post was split to a new topic: Count


#5

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