Using dict.get
How often have you aggregated an item by its group like this:
ar= [1,1,3,1,2,1,3,3,3,3]
pairs = {}
for i in ar:
if...
For further actions, you may consider blocking this person and/or reporting abuse
This is just too magical, and hard to understand.
A less magical version is
defaultdict
(from collections
)Diddo the swap from
to
you are absolutely right, I have updated the code. Thanks
You are right😁, fortunately there are several ways to do things in Python. I am more concerned about using dictionary methods. Thank you
Good walk of the different dictionary methods.
Thanks
I love the Counter object. I've had a rest API getting bogged down with pandas trying to count something and it took a few seconds for each response. Counter was just a few ms.
Great!
Great!
Thanks