Python Forum
How to take the rest of indeces
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to take the rest of indeces
#1
Hi all,
I am using the following method to take elements from a list.

this method takes from the list classes_samples the indexes that are given from the list below_zero_baseline_indexes
(itemgetter(*below_zero_baseline_indexes)(classes_samples))
now I would like to select all the other indeces that are not included in the initial list.

so if my list below_zero_baseline_indexes=[1,3,4]
I want to pick the [2,5]

is that possible?
Alex
Reply
#2
One way is to use set operations. Illustration of that idea:

>>> lst = list(range(1, 6))
>>> sample = [1, 3, 4]
>>> list(set(lst).difference(sample))
[2, 5]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Forum Jump:

User Panel Messages

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