Python‎ > ‎list‎ > ‎

list.count()

http://www.adilwaseem.com/

Definition
Return number of occurrences of value.

Syntax
L.count(value) -> integer

Parameters
None

Examples
The return with count of items in list.
 x=["Python","Lake","Learning", "Python"]
y=x.count("Python")
print("Total Number of Python in the list: ", y) 
>>> 
Total Number of Python in the list: 2
>>>

The method list the decimal value and limit the decimal point to '1.00' through quantize and then count the item string value.
from decimal import Decimal
list1=list()
list.append((Decimal(2.10).copy_negate().quantize(Decimal('1.00')),
                                 Decimal(1.3).copy_sign(Decimal(1.3)).quantize(Decimal('1.00')),
                                    Decimal(3).exp().quantize(Decimal('1.00')))
)
print("The items in the list1 are:,", list1)

>>> 
The items in the list1 are:, [(Decimal('-2.10'), Decimal('1.30'), Decimal('20.09'))]
>>>
>>> list1
[(Decimal('-2.10'), Decimal('1.30'), Decimal('20.09'))]
>>> list1.count('-2.10')
0
>>>

Comments