Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sequence slicing problem
#3
According to the documents:

s[i:j:k]

5.The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached

The last sentence says that if k (step) is negative, we start at the end and work back toward j (stop).

To do what you want you need to do two slices.

numbers[:5][::-2]
Reply


Messages In This Thread
sequence slicing problem - by qliu - Apr-27-2020, 08:14 PM
RE: sequence slicing problem - by stullis - Apr-27-2020, 09:08 PM
RE: sequence slicing problem - by deanhystad - Apr-27-2020, 09:23 PM
RE: sequence slicing problem - by Yoriz - Apr-27-2020, 09:30 PM
RE: sequence slicing problem - by deanhystad - Apr-27-2020, 09:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String slicing problem Ollew 4 2,807 Sep-08-2018, 08:07 PM
Last Post: Ollew
  Problem with slicing string YatishK 2 3,407 Apr-24-2017, 09:46 AM
Last Post: YatishK

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020