About 3,380,000 results
Open links in new tab
  1. python - Find a value in a list - Stack Overflow

    if list element is like an item ('ex' is in ['one,'example','two'] or 'example_1' is in ['one','example','two']): matches = [el for el in your_list if item in el] or. matches = [el for el in your_list if el in item] then just check len(matches) or read them if needed.

  2. python - Is there a simple way to delete a list element by value ...

    May 8, 2010 · Finding a value in a list and then deleting that index (if it exists) is easier done by just using list's remove method: >>> a = [1, 2, 3, 4] >>> try: ... a.remove(6) ... except ValueError: ... pass ... >>> print a [1, 2, 3, 4] >>> try: ... a.remove(3) ... except ValueError: ... pass ... >>> print a …

  3. How to access List elements in Python - Stack Overflow

    Aug 22, 2024 · Tried list[:][0] to show all first member for each list inside list is not working. Result will be the same as list[0][:]. So i use list comprehension like this: print([i[0] for i in list]) which return first element value for each list inside list.

  4. Access List Items in Python - GeeksforGeeks

    Dec 16, 2024 · Indexing is the simplest and most direct way to access specific items in a list. Every item in a list has an index starting from 0. Other methods that we can we use to access list elements are : List comprehension is a more advanced and efficient way to access list items.

  5. Check if element exists in list in Python - GeeksforGeeks

    Nov 29, 2024 · In this article, we will explore various methods to check if element exists in list in Python. The simplest way to check for the presence of an element in a list is using the in Keyword. Using for loop we can iterate over each element in the list and check if an element exists. Using this method, we have an extra control during checking elements.

  6. Python - Access List Items - W3Schools

    List items are indexed and you can access them by referring to the index number: Print the second item of the list: Note: The first item has index 0. Negative indexing means start from the end. Print the last item of the list: You can specify a range of indexes by specifying where to start and where to end the range.

  7. Python List index() – Find Index of Item | GeeksforGeeks

    Apr 27, 2025 · index () method in Python is a helpful tool when you want to find the position of a specific item in a list. It works by searching through the list from the beginning and returning the index (position) of the first occurrence of the element you’re looking for. Example: [/GFGTABS]

  8. Python Lists - Python Guides

    Add Elements to an Empty List in Python; Remove None Values from a List in Python; Find the Largest Number in a List Using Python; Divide Each Element in a List by a Number in Python; Find the Closest Value in a List Using Python; Check if Any Element in a List is Present in Another List using Python; Add an Element to the Beginning of a List ...

  9. 5 Best Ways to Search for an Element in a Python List

    Feb 26, 2024 · The ‘in’ operator is a straightforward way to check if an element exists in a list. It returns True if the element is found, otherwise False. This operation has a time complexity of O (n), as it may need to inspect each item in the list. Here’s an example: Output: True.

  10. Python List: How To Create, Sort, Append, Remove, And More

    Sep 10, 2024 · So you can convert anything iterable into a list. E.g., you can materialize the range function into a list of actual values or convert a Python set or tuple into a list: To access an individual list element, you need to know its position.

Refresh