1

Using the function row[3::2] will return the row from every 2nd column starting from the 3rd column.

But how can you adjust it so it returns up to a certain column? That is, how can you adjust it so it only gets every 2nd column up to the nth column.

1
  • To go from 3 to n taking every other item would be row[3:n:2]. To take n items starting at 3 and taking every other would be something more like row[3::2][:n]. In that case it would probably make more sense to use something like itertools.islice Commented Feb 8, 2018 at 0:56

1 Answer 1

1

Slicing syntax is start: stop: step, so to return only up to a certain column you can use:

row[3:10:2]

It's also possible to chain indexers like this:

row[3:10][::2]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.