Python collections tutorial

Python collections tutorial

Python
In this post, we'll discuss the underrated Python collections package, which is part of the standard library. Collections allows you to utilize several data structures beyond base Python. How to get a count of all the elements in a list One very useful function in collections is the Counter method, which you can use to return a count of all the elements in a list. The Counter object that gets returned is also modifiable. Let's define a variable equal to the result above. Notice how we can add the number 20 to our Counter object without having to initialize it with a 0 value. Counter can also be used if you have a list of tuples. This can be handy if you want to count pairs of numbers or other…
Read More