symmetric_difference Output as Two Separate Lists












0















Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list.



L1 | L2
-------
a | a
b | d
c | e
d | g
e | h
f | i
| j


We can get the differences of these lists using set(L1).symmetric_difference(L2), but unfortunately that lumps the results together in a single list. For example, the output of list(set(L1).symmetric_difference(L2)) is ['c', 'b', 'h', 'i', 'j', 'f', 'g'].



Is there a way to obtain two separate lists of output from list(set(L1).symmetric_difference(L2)) like ['c', 'b', 'f',] and ['h', 'i', 'j', 'g'] instead?



Or is there a way to obtain two separate lists as output while comparing the two sets/lists against each other only once?










share|improve this question





























    0















    Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list.



    L1 | L2
    -------
    a | a
    b | d
    c | e
    d | g
    e | h
    f | i
    | j


    We can get the differences of these lists using set(L1).symmetric_difference(L2), but unfortunately that lumps the results together in a single list. For example, the output of list(set(L1).symmetric_difference(L2)) is ['c', 'b', 'h', 'i', 'j', 'f', 'g'].



    Is there a way to obtain two separate lists of output from list(set(L1).symmetric_difference(L2)) like ['c', 'b', 'f',] and ['h', 'i', 'j', 'g'] instead?



    Or is there a way to obtain two separate lists as output while comparing the two sets/lists against each other only once?










    share|improve this question



























      0












      0








      0








      Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list.



      L1 | L2
      -------
      a | a
      b | d
      c | e
      d | g
      e | h
      f | i
      | j


      We can get the differences of these lists using set(L1).symmetric_difference(L2), but unfortunately that lumps the results together in a single list. For example, the output of list(set(L1).symmetric_difference(L2)) is ['c', 'b', 'h', 'i', 'j', 'f', 'g'].



      Is there a way to obtain two separate lists of output from list(set(L1).symmetric_difference(L2)) like ['c', 'b', 'f',] and ['h', 'i', 'j', 'g'] instead?



      Or is there a way to obtain two separate lists as output while comparing the two sets/lists against each other only once?










      share|improve this question
















      Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list.



      L1 | L2
      -------
      a | a
      b | d
      c | e
      d | g
      e | h
      f | i
      | j


      We can get the differences of these lists using set(L1).symmetric_difference(L2), but unfortunately that lumps the results together in a single list. For example, the output of list(set(L1).symmetric_difference(L2)) is ['c', 'b', 'h', 'i', 'j', 'f', 'g'].



      Is there a way to obtain two separate lists of output from list(set(L1).symmetric_difference(L2)) like ['c', 'b', 'f',] and ['h', 'i', 'j', 'g'] instead?



      Or is there a way to obtain two separate lists as output while comparing the two sets/lists against each other only once?







      arrays python-3.x list symmetric-difference






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 0:05







      Anthony

















      asked Nov 14 '18 at 23:31









      AnthonyAnthony

      1,375527




      1,375527
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can simply do the following:



          dif_1_from_2 = list(set(L1) - set(L2))
          dif_2_from_1 = list(set(L2) - set(L1))


          And you can create a function to do that like this:



          def get_symmetric_difference(L1, L2):
          return list(set(L1)-set(L2)), list(set(L2)-set(L1))


          and then you call it like this:



          print(get_symmetric_difference(L1, L2))


          Hope this helps.






          share|improve this answer


























          • ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

            – Anthony
            Nov 14 '18 at 23:46











          • Is my updated answer gives you what you asked in your comment? Please let me know.

            – TeeKea
            Nov 14 '18 at 23:48











          • no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

            – Anthony
            Nov 14 '18 at 23:50











          • Not sure, actually. I believe you would really need two operations to do that at the end.

            – TeeKea
            Nov 15 '18 at 0:21











          • ok, interesting. thanks anyways!!

            – Anthony
            Nov 15 '18 at 0:50











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53310328%2fsymmetric-difference-output-as-two-separate-lists%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can simply do the following:



          dif_1_from_2 = list(set(L1) - set(L2))
          dif_2_from_1 = list(set(L2) - set(L1))


          And you can create a function to do that like this:



          def get_symmetric_difference(L1, L2):
          return list(set(L1)-set(L2)), list(set(L2)-set(L1))


          and then you call it like this:



          print(get_symmetric_difference(L1, L2))


          Hope this helps.






          share|improve this answer


























          • ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

            – Anthony
            Nov 14 '18 at 23:46











          • Is my updated answer gives you what you asked in your comment? Please let me know.

            – TeeKea
            Nov 14 '18 at 23:48











          • no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

            – Anthony
            Nov 14 '18 at 23:50











          • Not sure, actually. I believe you would really need two operations to do that at the end.

            – TeeKea
            Nov 15 '18 at 0:21











          • ok, interesting. thanks anyways!!

            – Anthony
            Nov 15 '18 at 0:50
















          1














          You can simply do the following:



          dif_1_from_2 = list(set(L1) - set(L2))
          dif_2_from_1 = list(set(L2) - set(L1))


          And you can create a function to do that like this:



          def get_symmetric_difference(L1, L2):
          return list(set(L1)-set(L2)), list(set(L2)-set(L1))


          and then you call it like this:



          print(get_symmetric_difference(L1, L2))


          Hope this helps.






          share|improve this answer


























          • ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

            – Anthony
            Nov 14 '18 at 23:46











          • Is my updated answer gives you what you asked in your comment? Please let me know.

            – TeeKea
            Nov 14 '18 at 23:48











          • no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

            – Anthony
            Nov 14 '18 at 23:50











          • Not sure, actually. I believe you would really need two operations to do that at the end.

            – TeeKea
            Nov 15 '18 at 0:21











          • ok, interesting. thanks anyways!!

            – Anthony
            Nov 15 '18 at 0:50














          1












          1








          1







          You can simply do the following:



          dif_1_from_2 = list(set(L1) - set(L2))
          dif_2_from_1 = list(set(L2) - set(L1))


          And you can create a function to do that like this:



          def get_symmetric_difference(L1, L2):
          return list(set(L1)-set(L2)), list(set(L2)-set(L1))


          and then you call it like this:



          print(get_symmetric_difference(L1, L2))


          Hope this helps.






          share|improve this answer















          You can simply do the following:



          dif_1_from_2 = list(set(L1) - set(L2))
          dif_2_from_1 = list(set(L2) - set(L1))


          And you can create a function to do that like this:



          def get_symmetric_difference(L1, L2):
          return list(set(L1)-set(L2)), list(set(L2)-set(L1))


          and then you call it like this:



          print(get_symmetric_difference(L1, L2))


          Hope this helps.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 23:46

























          answered Nov 14 '18 at 23:41









          TeeKeaTeeKea

          3,22851731




          3,22851731













          • ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

            – Anthony
            Nov 14 '18 at 23:46











          • Is my updated answer gives you what you asked in your comment? Please let me know.

            – TeeKea
            Nov 14 '18 at 23:48











          • no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

            – Anthony
            Nov 14 '18 at 23:50











          • Not sure, actually. I believe you would really need two operations to do that at the end.

            – TeeKea
            Nov 15 '18 at 0:21











          • ok, interesting. thanks anyways!!

            – Anthony
            Nov 15 '18 at 0:50



















          • ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

            – Anthony
            Nov 14 '18 at 23:46











          • Is my updated answer gives you what you asked in your comment? Please let me know.

            – TeeKea
            Nov 14 '18 at 23:48











          • no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

            – Anthony
            Nov 14 '18 at 23:50











          • Not sure, actually. I believe you would really need two operations to do that at the end.

            – TeeKea
            Nov 15 '18 at 0:21











          • ok, interesting. thanks anyways!!

            – Anthony
            Nov 15 '18 at 0:50

















          ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

          – Anthony
          Nov 14 '18 at 23:46





          ok, thx, but is there no way to get the two lists of output while comparing the sets only once??

          – Anthony
          Nov 14 '18 at 23:46













          Is my updated answer gives you what you asked in your comment? Please let me know.

          – TeeKea
          Nov 14 '18 at 23:48





          Is my updated answer gives you what you asked in your comment? Please let me know.

          – TeeKea
          Nov 14 '18 at 23:48













          no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

          – Anthony
          Nov 14 '18 at 23:50





          no, unfortunately that's not what i meant. what i'm trying to get at it is that dif_1_from_2 compares the sets once, then dif_2_from_1 compares the sets for a 2nd time. is there no way to compare L1 and L2 once, but get two different lists as the output? does that make sense?

          – Anthony
          Nov 14 '18 at 23:50













          Not sure, actually. I believe you would really need two operations to do that at the end.

          – TeeKea
          Nov 15 '18 at 0:21





          Not sure, actually. I believe you would really need two operations to do that at the end.

          – TeeKea
          Nov 15 '18 at 0:21













          ok, interesting. thanks anyways!!

          – Anthony
          Nov 15 '18 at 0:50





          ok, interesting. thanks anyways!!

          – Anthony
          Nov 15 '18 at 0:50




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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.


          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%2fstackoverflow.com%2fquestions%2f53310328%2fsymmetric-difference-output-as-two-separate-lists%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

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values