`author_A = [['book_x',1,10],['book_y',2,20],['book_z',3,30]] author_B = [['book_s',5,10],['book_t',2,20],['book_z',3,30]] author_A AND author_B = ['book_z',3,30] author_A = [['book_x',1,10],['book_y',2,20]] author_B = [['book_s',5,10],['book_t',2,20]] --------------------------------------------- `

I Want present data like this

` author quantity Amount($) A&B 3 30 A 3 30 B 7 30 total 13 90 `

I DO NOT Want present data like this !!! in this case it's ADDED duplicate ['book_z',3,30]

` author quantity Amount($) A 6 60 B 10 60 total 16 120 `

that is my problems ,Anybody Please help me to sove this problems. Thanks everybody

-------------Problems Reply------------

`author_A = [['book_x',1,10],['book_y',2,20],['book_z',3,30]]`

author_B = [['book_s',5,10],['book_t',2,20],['book_z',3,30]]

```
```def present(A, B):

Aset = set(tuple(x) for x in A)

Bset = set(tuple(x) for x in B)

both = Aset & Bset

justA = Aset - both

justB = Bset - both

totals = [0, 0]

print "%-12s %-12s %12s" % ('author', 'quantity', 'Amount($)')

for subset, name in zip((both, justA, justB), ('A*B', 'A', 'B')):

tq = sum(x[1] for x in subset)

ta = sum(x[2] for x in subset)

totals[0] += tq

totals[1] += ta

print ' %-11s %-11d %-11d' % (name, tq, ta)

print ' %-11s %-11d %-11d' % ('total', totals[0], totals[1])

`present(author_A, author_B)`

I've tried to reproduce your desired weird format with some numbers left-aligned and totally funky spacing, but I'm sure you'll need to tweak the formatting in the various print statements to get the exact (and totally weird) formatting effect of your examples. However, apart from the spacing and left- vs right- alignment of the output, this should otherwise be exactly what you request.

You can find the intersections and exclusive ones like this...

`A_and_B = [a for a in author_A if a in author_B]`

only_A = [a for a in author_A if a not in author_B]

only_B = [b for b in author_B if b not in author_A]

then it is only a matter of printing them...

`print '%s %d %d' % tuple(A_and_B)`

print '%s %d %d' % tuple(only_A)

print '%s %d %d' % tuple(only_B)

Hope that helps

`books = {`

'A':[['book_x',1,10],['book_y',2,20]],

'B':[['book_s',5,10],['book_t',2,20]],

'A & B':[['book_z',3,30]],

}

for key in books:

quantity = []

amount = []

for item in books[key]:

quantity.append(item[1])

amount.append(item[2])

print ("%s\t%s\t%s") % (key,sum(quantity),sum(amount))