Re: Comparing values of counter in python 3.3
On 16/12/2013 02:40, Roy Smith wrote: In article 905d6e7e-6748-42dd-8b63-d80a4d175...@googlegroups.com, rusi rustompm...@gmail.com wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Counters are awesome. Yes -- agreed. But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. Bag and multiset are names only CS weenies would think to look for. Counter is the name for the rest of us :-) Give me bag or multiset any day of the week, it's blatantly obvious what they do. Counter, what the heck? :) -- 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
Re: Comparing values of counter in python 3.3
On Sun, Dec 15, 2013 at 6:32 PM, rusi rustompm...@gmail.com wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Because you get different counts. c1 = Counter('ab') c2 = Counter('aab') c2 - c1 Counter({'a': 1}) [(k, c2[k]) for k in c2 - c1] [('a', 2)] Counter subtraction is multiset subtraction, not set subtraction. -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On 12/12/2013 5:49 PM, Amjad Syed wrote: Hello, I have 2 counters generated from list using Collections.counter() 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] # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Counters are awesome. -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Counters are awesome. Yes -- agreed. But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On Mon, Dec 16, 2013 at 1:32 PM, rusi rustompm...@gmail.com wrote: But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. Which is why we have this list. Question: Is there a way to do x, y, and z, in Python? Answer: Check out this module! *returns time machine keys to Guido* ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
In article 905d6e7e-6748-42dd-8b63-d80a4d175...@googlegroups.com, rusi rustompm...@gmail.com wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Counters are awesome. Yes -- agreed. But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. Bag and multiset are names only CS weenies would think to look for. Counter is the name for the rest of us :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
On Monday, December 16, 2013 8:10:57 AM UTC+5:30, Roy Smith wrote: rusi wrote: On Monday, December 16, 2013 7:29:31 AM UTC+5:30, alex23 wrote: # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key [(k,Counter2[k]) for k in Counter2 - Counter1] Why not just? Counter2 - Counter1 And if you want to uncounterify it then dict(Counter2 - Counter1) Counters are awesome. Yes -- agreed. But 'counter' is a strange name -- after checking whether 'bag' and 'multiset' are there in the library, I would not think to check anything else. Bag and multiset are names only CS weenies would think to look for. Counter is the name for the rest of us :-) Weenie? WEENIE?!? Harrumph! Im offended!! wink More seriously: One issue with all the new good stuff -- comprehensions, generator expressions, dict comprehensions etc is that the motivations/explanations are all couched imperatively. So 1. [something(v) for v in lst] is understood as 2. newlst = [] for v in lst: newlst.append(something(v)) and so the comprehension is just a one-liner for the for-loop [Witness Mark's comments earlier that the for loop is more readable] If instead the comprenension is seen as a programmers equivalent of the set theory expression 3. {something(v) | v ∈ lst } # if the unicode gods deign to allow! then they would be more easily appreciated and used. The extreme example of this is that the implementation of comprehensions were and continue to be wrong because of variable leakage because 1 is equivalenced to 2 rather than 3. To come back to the topic: Counter suggesting DO-ing counting whereas bag/multiset suggests BE-ing with counts; ie the one sounds imperative, the other declarative (which of course may mean its a CS-weenie speaking!) -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing values of counter in python 3.3
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
Re: Comparing values of counter in python 3.3
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
Comparing values of counter in python 3.3
Hello, I have 2 counters generated from list using Collections.counter() 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] # Need to compare values of counter and reject in function/routine in value in counter2 is higher then value in counter1 for a current key Thanks -- https://mail.python.org/mailman/listinfo/python-list