10 examples of 'find all index of element in list python' in Python

Every line of 'find all index of element in list python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
59def list_find(l, element):
60 for i, e in enumerate(l):
61 if e == element:
62 return i
63 return None
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

62def find_index(self, e):
63 for i in range(self._size):
64 if self._data[i] == e:
65 return i
66 return -1
4def find(arr, elem):
5 lo = 0
6 hi = len(arr) - 1
7 while lo < hi:
8 mid = (hi + lo) // 2
9 first = arr[lo]
10 middle = arr[mid]
11 last = arr[hi]
12
13 if first <= middle and elem >= first and elem <= middle:
14 return binary_search(arr, elem, lo, mid)
15 elif last >= middle and elem >= middle and elem <= last:
16 return binary_search(arr, elem, mid+1, hi)
17 elif elem >= first and elem <= middle:
18 hi = mid
19 else:
20 lo = mid + 1
21
22 if arr[lo] == elem:
23 return lo
24 return None
26@register.simple_tag
27def find_element(list, index, index2=1):
28 """
29 When you have list like: a = [(0, 10), (1, 20), (2, 30)] and you need to get value from tuple with first value == index
30 Usage:
31 {% find_element 1 %} will return 20
32 """
33 for x in list:
34 if x[0] == index:
35 return x[index2]
36 return None
51def posMin(list):
52 """ returns the index of the lowest value of a given list
53 if multiple highest values exist, the first is returned
54 """
55 m = list[0]
56 index = 0
57 for i, x in enumerate(list):
58 if x < m:
59 m = x
60 index = i
61 return index
45def find_index(xs, x):
46 return xs.index(x) - len(xs)
27def rindex(lst, item):
28 try:
29 return dropwhile(lambda x: lst[x] != item, reversed(xrange(len(lst)))).next()
30 except StopIteration:
31 raise ValueError, "rindex(lst, item): item not in list"
27def _count(elem: object, ls, index: int) -> int:
28 if index < len(ls):
29 if ls[index] == elem:
30 return 1 + _count(elem, ls, index + 1)
31 else:
32 return _count(elem, ls, index + 1)
33 return 0
1def seq_search(items, key):
2 """顺序查找"""
3 for index, item in enumerate(items):
4 if item == key:
5 return index
6 return -1
178def t_list(tokens, index):
179 if (t_address_or_t_binary_number(tokens, index)
180 and t_separator(tokens, index + 1)):
181 islist = 1
182 arg = 0
183 while islist:
184 islist = islist and t_separator(tokens, index + (arg * 2) + 1)
185 var_index = index + (arg * 2) + 2
186 islist = islist and t_address_or_t_binary_number(tokens, var_index)
187 if (t_endline(tokens, index + (arg * 2) + 3)
188 or (index + (arg * 2) + 3) == len(tokens)):
189 break
190 arg += 1
191 if islist:
192 return ((arg + 1) * 2) + 1
193 return 0

Related snippets