slicing a list but in downward fashion

L

Lee Sander

hi,
i have a list and i can get elements form it via slicing
L[start:stop]
but sometimes the start is > stop i.e. I want to go in the opposite
direction,eg
L[10:2],

mattab lets you do L(10:-1:2) to achive this, is there a way to do
this in python?
thanks
L
 
M

Mensanator

hi,
i have a list and i can get elements form it via slicing
L[start:stop]
but sometimes the start is > stop i.e. I want to go in the opposite
direction,eg
L[10:2],

mattab lets you do L(10:-1:2) to achive this, is there a way to do
this in python?
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
a[3:10:2] [4, 6, 8, 10]
a[10:3:-2]
[11, 9, 7, 5]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top