About 2,560,000 results
Open links in new tab
  1. python - How can I find the index for a given item in a list? - Stack ...

    Caveats Linear time-complexity in list length An index call checks every element of the list in order, until it finds a match. If the list is long, and if there is no guarantee that the value will be near the …

  2. In Python, how do I index a list with another list?

    14 I wasn't happy with any of these approaches, so I came up with a Flexlist class that allows for flexible indexing, either by integer, slice or index-list:

  3. python - Negative list index? - Stack Overflow

    18 List indexes of -x mean the xth item from the end of the list, so n[-1] means the last item in the list n. Any good Python tutorial should have told you this.

  4. python - How to find all occurrences of an element in a list - Stack ...

    index() will give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list for an element?

  5. python - How to get item's position in a list? - Stack Overflow

    Dec 13, 2008 · I am iterating over a list and I want to print out the index of the item if it meets a certain condition. How would I do this? Example: testlist = [1,2,3,5,3,1,2,1,6] for item in testlist: if

  6. Finding the index of elements based on a condition using python list ...

    86 In Python, you wouldn't use indexes for this at all, but just deal with the values— [value for value in a if value > 2]. Usually dealing with indexes means you're not doing something the best way.

  7. How to extract elements from a list using indices in Python?

    Aug 19, 2015 · Closed 6 years ago. If you have a list in python, and want to extract elements at indices 1, 2 and 5 into a new list, how would you do this? This is how I did it, but I'm not very satisfied:

  8. python - Does "IndexError: list index out of range" when trying to ...

    Aug 11, 2022 · The way Python indexing works is that it starts at 0, so the first number of your list would be [0]. You would have to print [52], as the starting index is 0 and therefore line 53 is [52].

  9. Getting indices of True values in a boolean list - Stack Overflow

    The range here enumerates elements of your list and since we want only those where self.states is True, we are applying a filter based on this condition. For Python > 3.0:

  10. python - Getting the index of the returned max or min item using max ...

    Mar 19, 2010 · 735 I'm using Python's max and min functions on lists for a minimax algorithm, and I need the index of the value returned by max() or min(). In other words, I need to know which move …