FAQ: Code Challenge: Lists - More Frequent Item

This community-built FAQ covers the “More Frequent Item” exercise from the lesson “Code Challenge: Lists”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise More Frequent Item

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

stuck with the last few questions in this course. Everytime I try and use 1st as an element name I get a syntax error until I change it to first or something similar. Is it an issue with the course or is there a different way to declare a parameter starting with an integer?

Hi seanos90!

I don’t think I have thought or tried to use a number in a variable like this yet. These types of questions :definitions and rules are easy to look up on the internet. Since I haven’t come across this yet (as a newer learner myself) I did some research, and it appears that you can’t have a variable start as a number.

The Rules

  • Variables names must start with a letter or an underscore, such as:
    • _underscore
    • underscore_
  • The remainder of your variable name may consist of letters, numbers and underscores.
    • password1
    • n00b
    • un_der_scores
  • Names are case sensitive.
    • case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.

Try to use an underscore before your _1st and see if that will work. The internet is pretty easy to find things like this. Thanks, I learned something new as well!

1 Like

This is why we recommend not using l as a variable, it can be confused with 1.


is a common name given to list objects in sample and exercise code. That is, elle-ess-tee, not one-ess-tee.

As mentioned above, variable names may not begin with a number, but may contain a number.

1 Like

Thank you for your reply :slight_smile: and Completely get that now, I ended up googling it too after a few more tries. I just don’t get why codecademy would use 1st in the exercises?

The one looks like an elle, but if we check the lesson, I’m betting it is lst, not 1st.

The why of it is representative of list, but we should avoid using reserved words as variable names so the author wrote, lst. Other authors make it more obvious by using, my_list or alist, etc.

I make it obvious by using a font where different characters look different

Can anyone tell me why the below code is returning the wrong variable?

I think it has to do with using an IF and then an ELIF statement but I can’t see why that would be:

#Write your function here
def more_frequent_item(lst,item1,item2):
  if lst.count('item1') >= lst.count('item2'):
    return item1 
  elif lst.count('item2') > lst.count('item1'):
    return item2 
#Uncomment the line below when your function is done
print(more_frequent_item([2, 3, 3, 2, 3, 2, 3, 2, 3], 2, 3))

I don’t think you need the quotes around item1 and item2 as part of .count(). I think what your function is doing is looking for the strings ‘item1’ and ‘item2’ in the list. It will get 0 for each of these so will always return item1.

1 Like