Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python collections

Shulou Source: shulou.com Published: 2022-06-01 04:58:40 09月28日 Update

This article will give you a detailed explanation on how to use python collections. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Use python collections

Python collections is the container data type, namely, lists, collections, tuples, dictionaries. The Collections module provides high-performance data types that enhance the code, making the work simpler and easier. It also provides many features, which are demonstrated using the Counter () function below.

The Counter () function takes an iterable object, such as a list or tuple, and returns an Counter dictionary. The key of the dictionary is the only element that exists in the iterator, and the value of each key is a count of the number of times that element appears in the iterator.

To create a Counter object, pass an iterative (list) to the Counter () function as follows.

Fromcollections import Countercount = Counter (['count: 3,' Counter: 2, 'Counter: 2,' averse: 1}) this is the end of the article on "how to use python collections". I hope the above can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Tags: Iterations functions dictionaries articles code elements objects data more types good practical concise content functions containers articles modules times knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Xiaomi MySQL Microsoft