> I want to print only key,values in Counter2 which have values > then > corresponding value in Counter1. > E.g > Counter1={97:1,99:2,196:2,198:1} > Counter2={97:1 ,99:3, 196:1,198:1} > > # Output > [99,3] >
Try: [[key, Counter2[key]] for key in Counter1 if Counter2[key] > Counter1[key]] for a start. If you can't guarantee that every key from Counter1 is also in Counter2 you could use something like: [[key, Counter2[key]] for key in Counter1 if key in Counter2 and Counter2[key] > Counter1[key]] Best, Wolfgang -- https://mail.python.org/mailman/listinfo/python-list