FAQ: Working with Lists in Python - Slicing Lists

This community-built FAQ covers the “Slicing Lists” exercise from the lesson “Working with Lists in Python”.

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

Computer Science
Data Science

FAQs on the exercise Slicing Lists

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!

5 posts were split to a new topic: Slicing Lists

A post was merged into an existing topic: Slicing Lists - end index

Usually if lists are short, it would be easy to find out the indexes for the slicing method list[start:end] .
However, if lists happen to be extremely long, finding the indexes for the desired items becomes difficult. Is there a way to address this problem, like a more convenient method?

I don’t think there is one size fits all solution, it depends. You might use the index method to find the index. But this might be problematic if you have duplicate values.

Play Silly Games win Silly Prizes: Can’t believe that worked :rofl:

insert Mr. Robot Hacker Man.gif
Can I get my sweet hoodie now ???

What about :: colon mean?
I found these example in slice

that [::-1] means go through the entire list, and the -1 means do it backward

x = ['a', 'b', 'c', 'd', 'e', 'f'] # look at entire list, go backward y = x[::-1] print(y) # look at entire list, use every 2nd entry z = x[::2] print(z)
1 Like