About 405,000 results
Open links in new tab
  1. list.index () function for Python that doesn't throw exception when ...

    Python's list.index(x) throws an exception if the item doesn't exist. Is there a better way to do this that doesn't require handling exceptions?

  2. python - How can I find the index for a given item in a list? - Stack ...

    The returned index is computed relative to the beginning of the full sequence rather than the start argument. Caveats Linear time-complexity in list length An index call checks every element of …

  3. Best way to handle list.index (might-not-exist) in python?

    Of course the question asks specifically about lists so the best solution is to use the try-except method, however the speed improvements (at least 20x here compared to try-except) offered …

  4. python - Why doesn't list have safe "get" method like dictionary ...

    172 Ultimately it probably doesn't have a safe .get method because a dict is an associative collection (values are associated with names) where it is inefficient to check if a key is present …

  5. Equivelant to rindex for lists in Python - Stack Overflow

    Jul 9, 2012 · AttributeError: 'list' object has no attribute 'rindex' Is there a way to get this without having to construct a big loop? I'd prefer not to use the reverse method if it can be avoided, as …

  6. Complexity of list.index (x) in Python - Stack Overflow

    May 6, 2011 · The "Index" that your link is talking about is the same as Get Item in the python.org wiki. You can see in the cpython source code that the index method is doing an O (n) search …

  7. Python __index__ special method - Stack Overflow

    Called to implement operator.index(), and whenever Python needs to losslessly convert the numeric object to an integer object (such as in slicing, or in the built-in bin(), hex() and oct() …

  8. How to remove an element from a list by index - Stack Overflow

    Dec 13, 2016 · How do I remove an element from a list by index? I found list.remove(), but this slowly scans the list for an item by value.

  9. list - Alternatives to index () in Python - Stack Overflow

    1 So for my assignment I must find a way in which I can work around this problem of printing 'YES' if a list contains the elements 1,2,3 in the consecutive order. It does not work if the list …

  10. 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?