About 464,000 results
Open links in new tab
  1. python - Finding and replacing elements in a list - Stack Overflow

    I have to search through a list and replace all occurrences of one element with another. So far my attempts in code are getting me nowhere, what is the best way to do this? For example, …

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

    map() implementation can be improved by calling replace via operator.methodcaller() (by about 20%) but still slower than list comprehension (as of Python 3.9). from operator import …

  3. Replace values in list using Python - Stack Overflow

    May 28, 2015 · As to hints: Get to know the tools that Python ofters, especially list (and for Python 3 also dict) comprehensions, the ternary operator, anonymous (lambda) functions, and …

  4. How to replace values at specific indexes of a python list?

    Python code rule number one, if it's not readable, no one's gonna look at it for long enough to get any useful information out of it. Always use descriptive variable names. Almost didn't catch the …

  5. python - How to replace elements in a list using dictionary lookup ...

    Jun 25, 2013 · How to replace elements in a list using dictionary lookup Asked 12 years, 4 months ago Modified 9 months ago Viewed 72k times

  6. python: replace elements in list with conditional

    Sep 21, 2015 · You're using python lists. In python (2.x), comparison of a list with an int will compare the types, not the values. So, your comparison results in True which is equivalent to …

  7. python - Replace None value in list? - Stack Overflow

    4 Starting Python 3.6 you can do it in shorter form: d = [f'{e}' for e in d] hope this helps to someone since, I was having this issue just a while ago.

  8. How do you replace a value in a 2D list in python? [closed]

    Feb 8, 2019 · How would I replace a number in this list using list.append() and a user input for the index position? For example: I would like to replace a 4 in the array with a 7.

  9. How to modify list entries during for loop? - Stack Overflow

    Sep 8, 2023 · In this example, the objective is to, using a Python 'for' loop, REMOVE from an array of integers any element that is perfectly divisible by 7: def modify_array(numbers):

  10. python - Replace the last element in a list with another list - Stack ...

    Jul 9, 2012 · Never use list.remove unless your removal criteria is to remove an element with a particular value, when you don't know/care where it is in the list.