Home > Backend Development > Python Tutorial > How to count the number of elements in a list in python

How to count the number of elements in a list in python

silencement
Release: 2019-05-25 16:22:02
Original
23877 people have browsed it

How to count the number of elements in a list in python

When using Python, the following scenarios usually occur:

How to count the number of elements in a list in python

For example, in the above list: 0 appears once , 1 appears 2 times, 2 appears 3 times, and 3 appears 2 times.

This article explains several methods for obtaining the number of occurrences of elements in Python.

There are many ways to get the number of occurrences of an element. Here I propose the following methods. In the following code, the parameters passed in are array = [1, 2, 3, 3, 2, 1 , 0, 2]

conuter() method

This method can quickly obtain the elements in the list The number of occurrences

How to count the number of elements in a list in python

count in the list, get the number of occurrences of each element

How to count the number of elements in a list in python

#Numpy fancy index , get the number of occurrences of each element

How to count the number of elements in a list in python

##

The above is the detailed content of How to count the number of elements in a list in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template