On 12/12/2013 09:55, Wolfgang Maier wrote:
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
Personal preference I suppose, but give me a for loop any day of the
week, guess I just find them more readable :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list