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)
| 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] |
no test coverage detected