About 384,000 results
Open links in new tab
  1. 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 …

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

    View the answers with numpy integration, numpy arrays are far more efficient than Python lists. If the list is short it's no problem making a copy of it from a Python list, if it isn't then perhaps you …

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

  4. 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 …

  5. 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 …

  6. Using Python's list index() method on a list of tuples or objects?

    74 Python's list type has an index () method that takes one parameter and returns the index of the first item in the list matching the parameter. For instance:

  7. Finding first and last index of some value in a list in Python

    Feb 6, 2009 · Is there any built-in methods that are part of lists that would give me the first and last index of some value, like: verts.IndexOf(12.345) verts.LastIndexOf(12.345)

  8. Difference between del, remove, and pop on lists in Python

    Related post on similar lines for set data structure - Runtime difference between set.discard and set.remove methods in Python?

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

  10. python - Class accessible by iterator and index - Stack Overflow

    Mar 19, 2019 · My class implements an iterator so I can do: for i in class(): But I want to be able to access the class by index as well: class()[1] How can I do that?