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

Method index

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

Provide an index of first occurence of item in the list. (or raise a ValueError if item not present) If item is not a string, will raise a TypeError. minindex and maxindex are also optional arguments s.index(x[, i[, j]]) return smallest k such that s[k] == x and i <= k < j

(self, item, minindex=0, maxindex=None)

Source from the content-addressed store, hash-verified

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)
97 If item is not a string, will raise a TypeError.
98 minindex and maxindex are also optional arguments
99 s.index(x[, i[, j]]) return smallest k such that s[k] == x and i <= k < j
100 """
101 if maxindex == None: maxindex = len(self)
102 minindex = max(0, minindex)-1
103 maxindex = min(len(self), maxindex)
104 if not isinstance(item, str): raise TypeError('Members of this object must be strings. You supplied \"%s\"' % type(item))
105 index = minindex
106 while index < maxindex:
107 index += 1
108 if item.lower() == self[index].lower():
109 return index
110 raise ValueError(': list.index(x): x not in list')
111
112 def insert(self, i, x):
113 """s.insert(i, x) same as s[i:i] = [x]

Callers 7

_VmBFunction · 0.45
recipe-284569.pyFile · 0.45
recipe-252123.pyFile · 0.45
_pop_funclistFunction · 0.45
ilinesFunction · 0.45
is_inbetweenMethod · 0.45
__makerexpMethod · 0.45

Calls 3

minFunction · 0.85
maxFunction · 0.50
lowerMethod · 0.45

Tested by

no test coverage detected