How to remove duplicate values (coordinates) in a list [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Removing duplicates from a list of lists

    9 answers




I would like to ask how to remove duplicates in this type of list



ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]


i tried set() but still makes an error of: unhashable list



ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]
fpoint=list(set(ppoint))
print (fpoint)


i want to get



[[1,2],[3,4],[5,6],[7,3]


i think set() works only on single value idexes, is there any alternative way for this?










share|improve this question













marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 9:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Removing duplicates from a list of lists

      9 answers




    I would like to ask how to remove duplicates in this type of list



    ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]


    i tried set() but still makes an error of: unhashable list



    ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]
    fpoint=list(set(ppoint))
    print (fpoint)


    i want to get



    [[1,2],[3,4],[5,6],[7,3]


    i think set() works only on single value idexes, is there any alternative way for this?










    share|improve this question













    marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau python
    Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 20 at 9:05


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Removing duplicates from a list of lists

        9 answers




      I would like to ask how to remove duplicates in this type of list



      ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]


      i tried set() but still makes an error of: unhashable list



      ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]
      fpoint=list(set(ppoint))
      print (fpoint)


      i want to get



      [[1,2],[3,4],[5,6],[7,3]


      i think set() works only on single value idexes, is there any alternative way for this?










      share|improve this question














      This question already has an answer here:




      • Removing duplicates from a list of lists

        9 answers




      I would like to ask how to remove duplicates in this type of list



      ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]


      i tried set() but still makes an error of: unhashable list



      ppoint=[[1,2],[1,2],[3,4],[5,6],[7,3],[3,4],[5,6]]
      fpoint=list(set(ppoint))
      print (fpoint)


      i want to get



      [[1,2],[3,4],[5,6],[7,3]


      i think set() works only on single value idexes, is there any alternative way for this?





      This question already has an answer here:




      • Removing duplicates from a list of lists

        9 answers








      python list






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 8:49









      LOURD

      11




      11




      marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 20 at 9:05


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 20 at 9:05


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          You can do like this,



          In [9]: list(set(map(tuple,ppoint)))
          Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]





          share|improve this answer




























            up vote
            0
            down vote













            You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.



            An if statement could look like:



            for coords in ppoint:
            if coords not in fpoint:
            newlist.append(coords)





            share|improve this answer




























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              You can do like this,



              In [9]: list(set(map(tuple,ppoint)))
              Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]





              share|improve this answer

























                up vote
                2
                down vote













                You can do like this,



                In [9]: list(set(map(tuple,ppoint)))
                Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]





                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  You can do like this,



                  In [9]: list(set(map(tuple,ppoint)))
                  Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]





                  share|improve this answer












                  You can do like this,



                  In [9]: list(set(map(tuple,ppoint)))
                  Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 8:51









                  Rahul K P

                  7,04121833




                  7,04121833
























                      up vote
                      0
                      down vote













                      You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.



                      An if statement could look like:



                      for coords in ppoint:
                      if coords not in fpoint:
                      newlist.append(coords)





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.



                        An if statement could look like:



                        for coords in ppoint:
                        if coords not in fpoint:
                        newlist.append(coords)





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.



                          An if statement could look like:



                          for coords in ppoint:
                          if coords not in fpoint:
                          newlist.append(coords)





                          share|improve this answer












                          You could just use an if statement? But if you take a look at the collections module, I'm sure ther would be an easier solution.



                          An if statement could look like:



                          for coords in ppoint:
                          if coords not in fpoint:
                          newlist.append(coords)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 20 at 8:53









                          Adam

                          1067




                          1067















                              Popular posts from this blog

                              To store a contact into the json file from server.js file using a class in NodeJS

                              Redirect URL with Chrome Remote Debugging Android Devices

                              Dieringhausen