tags:

views:

92

answers:

4

Given two sets

a = [5,3,4,1,2,6,7]
b = [1,2,4,9]
c = set(a) - set(b)
# c -> [5,3,6,7]

is it possible to count how many items were removed from set 'a' ?

+5  A: 

How about len(set(a)) - len(c)?

Edit: len(a) could be incorrect if a contains duplicates.

Fred Larson
Thanks Fred! That was very simple!
heapzero
+2  A: 

Assuming lack of duplicates: len(a)-len(c) otherwise try: len(set(a)) - len(c)

gorsky
What if you have duplicates ?
ChristopheD
Corrected, thanks.
gorsky
A: 
a = [5,3,4,1,2,6,7] 
b = [1,2,4,9] 
c = set(a) - set(b)

print len(c)
foxhop
This will print size of resultant set. Question refers to something else.
gorsky
+2  A: 

there might be a more efficient way, but

 len(set(a)-set(c))

will work

Andrew Jaffe
This is about as efficient as it gets (in Python)...
ChristopheD