"Tim Peters" <tim.pet...@gmail.com> wrote

result = set(list1) - set(list2)

Of course the result is a set then.

Which means that if there were duplicates in list1 you only get one copy in the result. As Tim says, whether that is good, bad or irrelevant depends on the problem context.

Maybe that will work fine in context, maybe not. I leave it as an exercise to figure out how to
change it back into a list (hint:  try the obvious way first ;-) ).

But that won't replace any missing duplicates.
If they are significant you'll probably need to stick with Kent's list comprehension approach.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to