About 15,900,000 results
Open links in new tab
  1. How to Replace Values in a List in Python? - GeeksforGeeks

    Jan 4, 2025 · In this method, we use lambda and map function to replace the value in the list. map() is a built-in function in python to iterate over a list without using any loop statement. A …

  2. python - Finding and replacing elements in a list - Stack Overflow

    >>> a=[1,2,3,4,5,1,2,3,4,5,1] >>> item_to_replace = 1 >>> replacement_value = 6 >>> indices_to_replace = [i for i,x in enumerate(a) if x==item_to_replace] >>> indices_to_replace …

  3. Python: Replace Item in List (6 Different Ways) - datagy

    Oct 19, 2021 · Learn how to replace an item or items in a Python list, including how to replace at an index, replacing values, replacing multiple values.

  4. python - Find and replace string values in list - Stack Overflow

    What I would like is to replace [br] with some fantastic value similar to <br /> and thus getting a new list: This is called a list comprehension. You can use, for example: Besides list …

  5. python replacing item in list - Stack Overflow

    Nov 23, 2012 · You can simply find the index of the second occurrence by traversing the list and storing the indexes whose elements are 'a' until you've found two: >>> appl = ['1', 'a', 'a', '2', 'a'] …

  6. 7 Efficient Ways to Replace Item in List in Python

    Jul 4, 2021 · To Replace Item In List in Python, we can make use of for loops, indexing, comprehension, map and lambda function, while loops, etc.

  7. How to Replace Values in a List Using Python? - Python Guides

    Mar 5, 2025 · Learn how to replace values in a list using Python with methods like indexing, list comprehension, and `map()`. This guide includes step-by-step examples.

  8. How to Replace an Item in a List in Python - GeekAndNerd

    In this article, we’ve covered various methods for replacing items in a list in Python, including using indexing, list comprehension, and the `enumerate()` function. We’ve also discussed …

  9. How to replace an item in a list Python - Altcademy Blog

    Sep 4, 2023 · In Python, to replace an item in a list, you refer to the list name followed by square brackets containing the index of the item you want to replace. In this code, …

  10. Python: Replacing/Updating Elements in a List (with Examples)

    Jun 6, 2023 · If you want to update or replace a single element or a slice of a list by its index, you can use direct assignment with the [] operator. This is usually the simplest and fastest way to …

Refresh