Deleting duplicates only if they are a certain kind of duplicate

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have a list of tuples like this:



1,a,b,1,1,b,1,a,a,b,a,1,b,a,b


I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1. Therefore, the desired result given the example input above would be:



1,a,b,1,1,b,b,a,1


I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b and b,a,1).



I would like it to work for generic length tuples too, for example:



1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b


would become



1,1,1,1,1,a,b,c,1,1,a,b









share|improve this question



























    up vote
    3
    down vote

    favorite












    I have a list of tuples like this:



    1,a,b,1,1,b,1,a,a,b,a,1,b,a,b


    I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1. Therefore, the desired result given the example input above would be:



    1,a,b,1,1,b,b,a,1


    I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b and b,a,1).



    I would like it to work for generic length tuples too, for example:



    1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b


    would become



    1,1,1,1,1,a,b,c,1,1,a,b









    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a list of tuples like this:



      1,a,b,1,1,b,1,a,a,b,a,1,b,a,b


      I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1. Therefore, the desired result given the example input above would be:



      1,a,b,1,1,b,b,a,1


      I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b and b,a,1).



      I would like it to work for generic length tuples too, for example:



      1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b


      would become



      1,1,1,1,1,a,b,c,1,1,a,b









      share|improve this question















      I have a list of tuples like this:



      1,a,b,1,1,b,1,a,a,b,a,1,b,a,b


      I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1. Therefore, the desired result given the example input above would be:



      1,a,b,1,1,b,b,a,1


      I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b and b,a,1).



      I would like it to work for generic length tuples too, for example:



      1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b


      would become



      1,1,1,1,1,a,b,c,1,1,a,b






      list-manipulation filtering






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 mins ago









      J. M. is computer-less♦

      94.8k10294454




      94.8k10294454










      asked 25 mins ago









      Daniel Wilson-Nunn

      1995




      1995




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
          l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]



          1, a, b, 1, 1, b, b, a, 1




          DeleteDuplicatesBy[Sort]@l1



          1, a, b, 1, 1, b




          list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
          l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]



          1, 1, 1, 1, 1, a, b, c, 1, 1, a, b




          DeleteDuplicatesBy[Sort]@l2



          1, 1, 1, 1, 1, a, b, c, 1, 1, a, b







          share|improve this answer






















            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f184084%2fdeleting-duplicates-only-if-they-are-a-certain-kind-of-duplicate%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
            l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]



            1, a, b, 1, 1, b, b, a, 1




            DeleteDuplicatesBy[Sort]@l1



            1, a, b, 1, 1, b




            list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
            l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]



            1, 1, 1, 1, 1, a, b, c, 1, 1, a, b




            DeleteDuplicatesBy[Sort]@l2



            1, 1, 1, 1, 1, a, b, c, 1, 1, a, b







            share|improve this answer


























              up vote
              4
              down vote













              list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
              l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]



              1, a, b, 1, 1, b, b, a, 1




              DeleteDuplicatesBy[Sort]@l1



              1, a, b, 1, 1, b




              list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
              l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]



              1, 1, 1, 1, 1, a, b, c, 1, 1, a, b




              DeleteDuplicatesBy[Sort]@l2



              1, 1, 1, 1, 1, a, b, c, 1, 1, a, b







              share|improve this answer
























                up vote
                4
                down vote










                up vote
                4
                down vote









                list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
                l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]



                1, a, b, 1, 1, b, b, a, 1




                DeleteDuplicatesBy[Sort]@l1



                1, a, b, 1, 1, b




                list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
                l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]



                1, 1, 1, 1, 1, a, b, c, 1, 1, a, b




                DeleteDuplicatesBy[Sort]@l2



                1, 1, 1, 1, 1, a, b, c, 1, 1, a, b







                share|improve this answer














                list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
                l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]



                1, a, b, 1, 1, b, b, a, 1




                DeleteDuplicatesBy[Sort]@l1



                1, a, b, 1, 1, b




                list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
                l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]



                1, 1, 1, 1, 1, a, b, c, 1, 1, a, b




                DeleteDuplicatesBy[Sort]@l2



                1, 1, 1, 1, 1, a, b, c, 1, 1, a, b








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 15 mins ago

























                answered 21 mins ago









                kglr

                166k8188388




                166k8188388



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184084%2fdeleting-duplicates-only-if-they-are-a-certain-kind-of-duplicate%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    List of Gilmore Girls characters

                    What does second last employer means? [closed]

                    One-line joke