MCPcopy Create free account
hub / github.com/ActiveState/code / count

Method count

recipes/Python/284569_caselessList/recipe-284569.py:85–93  ·  view source on GitHub ↗

Counts references to 'item' in a caseless manner. If item is not a string it will always return 0.

(self, item)

Source from the content-addressed store, hash-verified

83 list.append(self, entry)
84
85 def count(self, item):
86 """Counts references to 'item' in a caseless manner.
87 If item is not a string it will always return 0."""
88 if not isinstance(item, str): return 0
89 count = 0
90 for entry in self:
91 if item.lower() == entry.lower():
92 count += 1
93 return count
94
95 def index(self, item, minindex=0, maxindex=None):
96 """Provide an index of first occurence of item in the list. (or raise a ValueError if item not present)

Callers 4

recipe-284569.pyFile · 0.45
cmp_3sFunction · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 1

lowerMethod · 0.45

Tested by

no test coverage detected