FAQ: Introduction to Lists in Python - Accessing List Elements

This community-built FAQ covers the “Accessing List Elements” exercise from the lesson “Introduction to Lists in Python”.

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

Visualize Data with Python
Data Scientist
Analyze Data with Python
Computer Science
Analyze Financial Data with Python
Build Chatbots with Python
Build Python Web Apps with Flask
Data Analyst

Learn Python 3
CS101 Livestream Series

FAQs on the exercise Accessing List Elements

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

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

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

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

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

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!

I think there is an error in this exercise. The question asks you to use square brackets ( [ and ] ) to select the 4th employee from the list employees .
Because Pythons uses zero index, the fourth employee should be Ryan. When you write: print(employees[4]) , Ryan is the output. However, the model won’t let you progress unless you assign Pams name to the variable employee_four.

2 Likes

Please post a link to the exercise page.

I believe it is asking for the 4th person on the list, and being a zero index language I believe it wants print(employees[3])

1 Like

https://www.codecademy.com/courses/learn-python-3/lessons/create-python-list/exercises/accessing-list-elements

We can see that ‘Pam’ is the fourth name in the list. Index 4 would give us ‘Ryan’, but that is the fifth name. The instructions are clear in that they want the fourth name. That is at index 3.

2 Likes

Oh I see. I have been counting lists with the first element as ZERO in line with the way that list elements are indexed in Python, which I think is why I was confused. I didn’t realise that the questions are framed in a way that ask you to count the first element as the first (and then match it with the correct index, starting from 0) - confusing! This became more clear to me as I progressed through the working with lists modules and realised I was getting answers wrong because I was counting from 0 instead of first, second, third etc to find the right element. It’s starting to make more sense as I get used to it :slight_smile:

1 Like

also thank you @mtf !

1 Like

But, if we are trying to access the fourth element, how is

print(employees[4])

correct compared to

print(employee_four) or print(employees[3])

if our saved variable is

employee_four = employees[3]

It is not, since that would be employee_five.

Exactly. That is my same reaction but the program indicates that I am wrong.

Be sure to assign the employee variable to complete step 1.

which I did.

Because our lists are zero indexed, our fourth element is saved as:

employee_four = employees[3]

As such, because we want to display the fourth element our final result is:

print(employees[3])

Correction: I have the right answer now. I am still, somewhat, confused in terms of how I can get some answers wrong (even with the correct code) but at other times I am right.

print(employees[3])

is not the correct code. We are asked to print the variable.

Careful not to be deceived by confirmation bias. Easier to accept there is a possible error and find it than to be convinced there is no error and have it staring you in the face. Programmers must first learn responsibility so they can admit to and accept their mistakes.

1 Like

Right! Now I understand what I was not understanding. After taking a break, my issue was not understanding what the instructions were asking.

1 Like

It’s a fledgling mistake. Don’t beat yourself up. There is a whole universe opening up to you. Mistakes is how it becomes most evident. Pride yourself, and surge forward.

1 Like

I go confused by the question too. Fourth person on the list or person at index[3]? I did nested for loop.

for index in range(len(employees)): #scroll through list
if employee[3]: #Condition
employee_four = employees[3] #add to employee_four

print(employee_four)

We should learn about loops soon.

Yeah you get to loops a lot more later, not sure why it doesn’t show what you need before this exercise.

THANK YOU!! I said the same thing.

I have a question.

Even not declaring the employee 6, I could print it.
When I printed print(employees[6]), the answer was Robert, which is right.

So even if I do not declare the variable I can still call it from the list and print it?

My code is:

employees = [“Michael”, “Dwight”, “Jim”, “Pam”, “Ryan”, “Andy”, “Robert”]
employee_four = employees[3]
print(employees[6])

output: Robert