How to remove the item that is repeated?












3












$begingroup$


If i have a



list={m,n,p,q,q,r,l,l}


how can i remove the repeated item with pattern matching so i would have



modifiedlist={m,n,p,r}?









share|improve this question









$endgroup$








  • 2




    $begingroup$
    {a, b, a} - is a repeated here?
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    @Kuba yes it is.
    $endgroup$
    – user49047
    1 hour ago






  • 2




    $begingroup$
    Closely related: mathematica.stackexchange.com/q/40317/5478
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    Also related mathematica.stackexchange.com/q/107483/106
    $endgroup$
    – user1066
    28 mins ago
















3












$begingroup$


If i have a



list={m,n,p,q,q,r,l,l}


how can i remove the repeated item with pattern matching so i would have



modifiedlist={m,n,p,r}?









share|improve this question









$endgroup$








  • 2




    $begingroup$
    {a, b, a} - is a repeated here?
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    @Kuba yes it is.
    $endgroup$
    – user49047
    1 hour ago






  • 2




    $begingroup$
    Closely related: mathematica.stackexchange.com/q/40317/5478
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    Also related mathematica.stackexchange.com/q/107483/106
    $endgroup$
    – user1066
    28 mins ago














3












3








3





$begingroup$


If i have a



list={m,n,p,q,q,r,l,l}


how can i remove the repeated item with pattern matching so i would have



modifiedlist={m,n,p,r}?









share|improve this question









$endgroup$




If i have a



list={m,n,p,q,q,r,l,l}


how can i remove the repeated item with pattern matching so i would have



modifiedlist={m,n,p,r}?






pattern-matching






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









user49047user49047

19510




19510








  • 2




    $begingroup$
    {a, b, a} - is a repeated here?
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    @Kuba yes it is.
    $endgroup$
    – user49047
    1 hour ago






  • 2




    $begingroup$
    Closely related: mathematica.stackexchange.com/q/40317/5478
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    Also related mathematica.stackexchange.com/q/107483/106
    $endgroup$
    – user1066
    28 mins ago














  • 2




    $begingroup$
    {a, b, a} - is a repeated here?
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    @Kuba yes it is.
    $endgroup$
    – user49047
    1 hour ago






  • 2




    $begingroup$
    Closely related: mathematica.stackexchange.com/q/40317/5478
    $endgroup$
    – Kuba
    1 hour ago










  • $begingroup$
    Also related mathematica.stackexchange.com/q/107483/106
    $endgroup$
    – user1066
    28 mins ago








2




2




$begingroup$
{a, b, a} - is a repeated here?
$endgroup$
– Kuba
1 hour ago




$begingroup$
{a, b, a} - is a repeated here?
$endgroup$
– Kuba
1 hour ago












$begingroup$
@Kuba yes it is.
$endgroup$
– user49047
1 hour ago




$begingroup$
@Kuba yes it is.
$endgroup$
– user49047
1 hour ago




2




2




$begingroup$
Closely related: mathematica.stackexchange.com/q/40317/5478
$endgroup$
– Kuba
1 hour ago




$begingroup$
Closely related: mathematica.stackexchange.com/q/40317/5478
$endgroup$
– Kuba
1 hour ago












$begingroup$
Also related mathematica.stackexchange.com/q/107483/106
$endgroup$
– user1066
28 mins ago




$begingroup$
Also related mathematica.stackexchange.com/q/107483/106
$endgroup$
– user1066
28 mins ago










3 Answers
3






active

oldest

votes


















3












$begingroup$

Select[list, Count[list, #] == 1 &]



{m, n, p, r}




Also



Select[list, Counts[list][#] == 1 &]



{m, n, p, r}




Keys@Select[Counts[list], # == 1 &]



{m, n, p, r}







share|improve this answer











$endgroup$













  • $begingroup$
    very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
    $endgroup$
    – user49047
    1 hour ago










  • $begingroup$
    @user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
    $endgroup$
    – kglr
    1 hour ago










  • $begingroup$
    The method using Counts is probably the best way, since you only have to traverse the whole list once.
    $endgroup$
    – Sjoerd Smit
    1 hour ago










  • $begingroup$
    @SjoerdSmit, excellent point.
    $endgroup$
    – kglr
    1 hour ago



















3












$begingroup$

First /@ Select[Tally@list, Last@# == 1 &]



{m, n, p, r}




or



First /@ Cases[Tally@list, {_, 1}]



{m, n, p, r}







share|improve this answer









$endgroup$









  • 1




    $begingroup$
    Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
    $endgroup$
    – Michael E2
    50 mins ago



















-3












$begingroup$

DeleteDuplicates[{m, n, p, q, q, r, l, l}]
(*{m, n, p, q, r, l}*)





share|improve this answer









$endgroup$









  • 2




    $begingroup$
    @SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
    $endgroup$
    – Michael E2
    1 hour ago










  • $begingroup$
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    $endgroup$
    – corey979
    43 mins ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190074%2fhow-to-remove-the-item-that-is-repeated%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









3












$begingroup$

Select[list, Count[list, #] == 1 &]



{m, n, p, r}




Also



Select[list, Counts[list][#] == 1 &]



{m, n, p, r}




Keys@Select[Counts[list], # == 1 &]



{m, n, p, r}







share|improve this answer











$endgroup$













  • $begingroup$
    very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
    $endgroup$
    – user49047
    1 hour ago










  • $begingroup$
    @user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
    $endgroup$
    – kglr
    1 hour ago










  • $begingroup$
    The method using Counts is probably the best way, since you only have to traverse the whole list once.
    $endgroup$
    – Sjoerd Smit
    1 hour ago










  • $begingroup$
    @SjoerdSmit, excellent point.
    $endgroup$
    – kglr
    1 hour ago
















3












$begingroup$

Select[list, Count[list, #] == 1 &]



{m, n, p, r}




Also



Select[list, Counts[list][#] == 1 &]



{m, n, p, r}




Keys@Select[Counts[list], # == 1 &]



{m, n, p, r}







share|improve this answer











$endgroup$













  • $begingroup$
    very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
    $endgroup$
    – user49047
    1 hour ago










  • $begingroup$
    @user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
    $endgroup$
    – kglr
    1 hour ago










  • $begingroup$
    The method using Counts is probably the best way, since you only have to traverse the whole list once.
    $endgroup$
    – Sjoerd Smit
    1 hour ago










  • $begingroup$
    @SjoerdSmit, excellent point.
    $endgroup$
    – kglr
    1 hour ago














3












3








3





$begingroup$

Select[list, Count[list, #] == 1 &]



{m, n, p, r}




Also



Select[list, Counts[list][#] == 1 &]



{m, n, p, r}




Keys@Select[Counts[list], # == 1 &]



{m, n, p, r}







share|improve this answer











$endgroup$



Select[list, Count[list, #] == 1 &]



{m, n, p, r}




Also



Select[list, Counts[list][#] == 1 &]



{m, n, p, r}




Keys@Select[Counts[list], # == 1 &]



{m, n, p, r}








share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 1 hour ago









kglrkglr

180k9200413




180k9200413












  • $begingroup$
    very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
    $endgroup$
    – user49047
    1 hour ago










  • $begingroup$
    @user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
    $endgroup$
    – kglr
    1 hour ago










  • $begingroup$
    The method using Counts is probably the best way, since you only have to traverse the whole list once.
    $endgroup$
    – Sjoerd Smit
    1 hour ago










  • $begingroup$
    @SjoerdSmit, excellent point.
    $endgroup$
    – kglr
    1 hour ago


















  • $begingroup$
    very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
    $endgroup$
    – user49047
    1 hour ago










  • $begingroup$
    @user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
    $endgroup$
    – kglr
    1 hour ago










  • $begingroup$
    The method using Counts is probably the best way, since you only have to traverse the whole list once.
    $endgroup$
    – Sjoerd Smit
    1 hour ago










  • $begingroup$
    @SjoerdSmit, excellent point.
    $endgroup$
    – kglr
    1 hour ago
















$begingroup$
very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
$endgroup$
– user49047
1 hour ago




$begingroup$
very nice i added {m,n,p,q,q,r,l,l} /. a_List :> Select[a, Count[a, #] == 1 &]
$endgroup$
– user49047
1 hour ago












$begingroup$
@user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
$endgroup$
– kglr
1 hour ago




$begingroup$
@user49047, Select[a, Count[a, #] == 1 &] gives you the result directly; you don't need to use ReplaceAll.
$endgroup$
– kglr
1 hour ago












$begingroup$
The method using Counts is probably the best way, since you only have to traverse the whole list once.
$endgroup$
– Sjoerd Smit
1 hour ago




$begingroup$
The method using Counts is probably the best way, since you only have to traverse the whole list once.
$endgroup$
– Sjoerd Smit
1 hour ago












$begingroup$
@SjoerdSmit, excellent point.
$endgroup$
– kglr
1 hour ago




$begingroup$
@SjoerdSmit, excellent point.
$endgroup$
– kglr
1 hour ago











3












$begingroup$

First /@ Select[Tally@list, Last@# == 1 &]



{m, n, p, r}




or



First /@ Cases[Tally@list, {_, 1}]



{m, n, p, r}







share|improve this answer









$endgroup$









  • 1




    $begingroup$
    Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
    $endgroup$
    – Michael E2
    50 mins ago
















3












$begingroup$

First /@ Select[Tally@list, Last@# == 1 &]



{m, n, p, r}




or



First /@ Cases[Tally@list, {_, 1}]



{m, n, p, r}







share|improve this answer









$endgroup$









  • 1




    $begingroup$
    Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
    $endgroup$
    – Michael E2
    50 mins ago














3












3








3





$begingroup$

First /@ Select[Tally@list, Last@# == 1 &]



{m, n, p, r}




or



First /@ Cases[Tally@list, {_, 1}]



{m, n, p, r}







share|improve this answer









$endgroup$



First /@ Select[Tally@list, Last@# == 1 &]



{m, n, p, r}




or



First /@ Cases[Tally@list, {_, 1}]



{m, n, p, r}








share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









JerryJerry

1,142112




1,142112








  • 1




    $begingroup$
    Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
    $endgroup$
    – Michael E2
    50 mins ago














  • 1




    $begingroup$
    Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
    $endgroup$
    – Michael E2
    50 mins ago








1




1




$begingroup$
Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
$endgroup$
– Michael E2
50 mins ago




$begingroup$
Cases seems to be fastest so far on large lists. Cases[Tally@list, {_, 1}][[All, 1]] is about 10% faster on unpacked arrays, slightly slower on packed arrays.
$endgroup$
– Michael E2
50 mins ago











-3












$begingroup$

DeleteDuplicates[{m, n, p, q, q, r, l, l}]
(*{m, n, p, q, r, l}*)





share|improve this answer









$endgroup$









  • 2




    $begingroup$
    @SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
    $endgroup$
    – Michael E2
    1 hour ago










  • $begingroup$
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    $endgroup$
    – corey979
    43 mins ago
















-3












$begingroup$

DeleteDuplicates[{m, n, p, q, q, r, l, l}]
(*{m, n, p, q, r, l}*)





share|improve this answer









$endgroup$









  • 2




    $begingroup$
    @SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
    $endgroup$
    – Michael E2
    1 hour ago










  • $begingroup$
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    $endgroup$
    – corey979
    43 mins ago














-3












-3








-3





$begingroup$

DeleteDuplicates[{m, n, p, q, q, r, l, l}]
(*{m, n, p, q, r, l}*)





share|improve this answer









$endgroup$



DeleteDuplicates[{m, n, p, q, q, r, l, l}]
(*{m, n, p, q, r, l}*)






share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









Ulrich NeumannUlrich Neumann

8,149516




8,149516








  • 2




    $begingroup$
    @SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
    $endgroup$
    – Michael E2
    1 hour ago










  • $begingroup$
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    $endgroup$
    – corey979
    43 mins ago














  • 2




    $begingroup$
    @SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
    $endgroup$
    – Michael E2
    1 hour ago










  • $begingroup$
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    $endgroup$
    – corey979
    43 mins ago








2




2




$begingroup$
@SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
$endgroup$
– Michael E2
1 hour ago




$begingroup$
@SjoerdSmit It clearly does not do what the OP wants, which is to remove all items that are duplicated, not just the extra ones. Compare with the desired output in the OP.
$endgroup$
– Michael E2
1 hour ago












$begingroup$
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
$endgroup$
– corey979
43 mins ago




$begingroup$
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
$endgroup$
– corey979
43 mins ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190074%2fhow-to-remove-the-item-that-is-repeated%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to label and detect the document text images

Vallis Paradisi

Tabula Rosettana