Monday, 26 August 2013

Python Indexing with List of Indices to Exclude

Python Indexing with List of Indices to Exclude

This is similar to some other questions (Explicitly select items from a
Python list or tuple, Grabbing specific indices of a list in Python), but
I'm looking to do the opposite:
What is a clean way to specify a list/tuple of indices to exclude, instead
of to select? I'm thinking of something similar to R or MATLAB where you
can specify indices to exclude, like:
vector1 <- c('a', 'b', 'c', 'd')
vector2 <- vector1[-1] # ['b', 'c', 'd']
vector3 <- vector1[c(-1, -2)] # ['c', 'd']
Is there a good way to accomplish the same thing in Python? Apologizes if
this is a dupe, I wasn't sure exactly what to search for.

No comments:

Post a Comment