By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

slicing a list but in downward fashion

P: n/a
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
Mar 19 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mar 19, 6:37*pm, Lee Sander <lesa...@gmail.comwrote:
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]
thanks
L
Mar 20 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.