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?
python list
marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau
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.
add a comment |
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?
python list
marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau
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.
add a comment |
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?
python list
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
python list
asked Nov 20 at 8:49
LOURD
11
11
marked as duplicate by Bram Vanroy, MedAli, Mike Scotty, martineau
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
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.
add a comment |
add a comment |
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)]
add a comment |
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)
add a comment |
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)]
add a comment |
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)]
add a comment |
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)]
You can do like this,
In [9]: list(set(map(tuple,ppoint)))
Out[9]: [(1, 2), (5, 6), (3, 4), (7, 3)]
answered Nov 20 at 8:51
Rahul K P
7,04121833
7,04121833
add a comment |
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered Nov 20 at 8:53
Adam
1067
1067
add a comment |
add a comment |