Given开发者_JS百科 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' ?
How about len(set(a)) - len(c)?
Edit: len(a) could be incorrect if a contains duplicates.
there might be a more efficient way, but
len(set(a)-set(c))
will work
Assuming lack of duplicates:
len(a)-len(c)
otherwise try:
len(set(a)) - len(c)
a = [5,3,4,1,2,6,7]
b = [1,2,4,9]
c = set(a) - set(b)
print len(c)
加载中,请稍侯......
精彩评论