Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

This question is somewhat related to How to efficiently find positions of duplicates?How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3 and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1 and 2 from myList are all considered duplicates.

Thank you very much.

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3 and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1 and 2 from myList are all considered duplicates.

Thank you very much.

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3 and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1 and 2 from myList are all considered duplicates.

Thank you very much.

added 11 characters in body; edited tags
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewListmyNewList, the duplicates occurred at positions 2,3,2,3 and 44. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1,3,1 and 22 from myListmyList are all considered duplicates.

Thank you very much.

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3, and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1, and 2 from myList are all considered duplicates.

Thank you very much.

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3 and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1 and 2 from myList are all considered duplicates.

Thank you very much.

Tweeted twitter.com/StackMma/status/689474784120307712
Source Link
Rohit
  • 201
  • 1
  • 3

Easiest/most efficient way to delete duplicates from one list at the positions of another?

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the positions of duplicates in a list. I just want to delete duplicates of a given list based on the duplicates of another list.

As a simple example, let's say I have one list

myList = {1,3,1,2}; 

I perform some operations on this list, which yields a different list, but preserves the length

myNewList = {7,2,2,2}; 

After deleting duplicates, this list now becomes

myNewListReduced = {7,2}; 

Now, I would like to remove elements from my original list wherever the duplicates occurred in the new list. I do not necessarily care which of the positions are removed. In myNewList, the duplicates occurred at positions 2,3, and 4. I would like to delete elements in my original list corresponding to that definition of duplicates, so that the following are all acceptable:

myListDuplicatesDeleted = {1,3}; myListDuplicatesDeleted = {1,1}; myListDuplicatesDeleted = {1,2}; 

That is, 3,1, and 2 from myList are all considered duplicates.

Thank you very much.