Ommiting Indices


#1



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


It says
Oops, try again.
Make sure to omit the appropriate indices in your list slice. Check the Hint if you need help!


Which makes absolutely no sense. Did I not do that...?


my_list = range(1, 11) # List of numbers 1 - 10

# Add your code below!
print my_list[0:10:2]


#2

Instructions are to omit start and stop indexes, where do you mean that you did that? They look very much there to me. Have you had a closer look at the examples in the instructions?


#3

my_list = range(1, 11) # List of numbers 1 - 10

print my_list[::2]

From the start you only need to print every second number. so the code above would print , 1,3,5,7,9
Take a look at the example

to_five = ['A', 'B', 'C', 'D', 'E']
print to_five[::2]

Will print ['A', 'C', 'E']


#4

you are to omit the start and stop:
[start:stop:stride}
in this form:
my_list = range(1, 11) # List of numbers 1 - 10

Add your code below!

print my_list[::2]


#5

Thanks, the code worked~!


#6

your are welcome.:sunglasses:


#7

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