Need help with list slicing


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/1/2?curriculum_id=4f89dab3d788890003000096#


Oops, try again. It looks like your first slice is ["sunglasses"] instead of ["sunglasses", "hat"].


its supposed to return "sunglasses","hat"


suitcase = ["sunglasses","hat","passport","laptop","suit", "shoes"]

first = suitcase[0:1]  
middle = suitcase[2:3]   
last = suitcase[4:5]


#2

Lists are 0-indexed.

what does that mean?

suppose.. x is a list.

x = ['a','b','c','d','e','f','g']

at index 0 -- > 'a'
at index 1 -- > 'b'
at index 2 -- > 'c'
at index 3 -- > 'd'
at index 4 -- > 'e'
at index 5 -- > 'f'
at index 6 -- > 'g'

when we slice a list like this..

x[2:4] It will start slicing from index 2 to 3 excluding 4

so x[2:4] will be ["c","d"]

You made mistake while slicing.
do reply if you get it or not.


#3

thank you but I figured it out


#4

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