python set difference
Posted
by
user1311992
on Stack Overflow
See other posts from Stack Overflow
or by user1311992
Published on 2012-04-04T05:25:20Z
Indexed on
2012/04/04
5:28 UTC
Read the original article
Hit count: 259
I'm doing a set difference operation in Python:
from sets import Set
from mongokit import ObjectId
x = [ObjectId("4f7aba8a43f1e51544000006"), ObjectId("4f7abaa043f1e51544000007"), ObjectId("4f7ac02543f1e51a44000001")]
y = [ObjectId("4f7acde943f1e51fb6000003")]
print list(Set(x).difference(Set(y)))
I'm getting:
[ObjectId('4f7abaa043f1e51544000007'), ObjectId('4f7ac02543f1e51a44000001'), ObjectId('4f7aba8a43f1e51544000006')]
I need to get the first element for next operation which is important. How can I retain the list x
in original format?
© Stack Overflow or respective owner