Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

replace a string in a list

list = ['helloXXX', 'welcomeXXX', 'to999', 'SofthuntUUU']
replace = [list.replace('XXX', 'ZZZ') for list in list]
print(replace)
Comment

list python replace

# Replace 'Koweit' To 'Sudan'
my_list = [ "Egypt", "Koweit", "Algeria", "Morocco", "Tunisia" ]
my_list[ 1 ] = "Sudan"
print( my_list )
Comment

python how to replace a string in a list

# Replace a particular item in a Python list
a_list = ['aple', 'orange', 'aple', 'banana', 'grape', 'aple']
for i in range(len(a_list)):
    if a_list[i] == 'aple':
        a_list[i] = 'apple'
print(a_list)
# Returns: ['apple', 'orange', 'apple', 'banana', 'grape', 'apple']
Comment

Replace an item in a python list

# Replace Values in a List using Slicing
  
# define list
l = ['Hardik', 'Rohit', 'Rahul', 'Virat', 'Pant']
  
# find the index of Rahul
i = l.index('Rahul')
  
# replace Rahul with Shikhar
l = l[:i]+['Shikhar']+l[i+1:]
  
# print list
print(l)
Comment

PREVIOUS NEXT
Code Example
Python :: use datetime python to get runtime 
Python :: python string math 
Python :: parquet to dataframe 
Python :: selenium assert text on page python 
Python :: tkinter button foreground color click 
Python :: install from github 
Python :: numpy generate random 2d array 
Python :: python set recursion limit 
Python :: login_required 
Python :: python get number of days 
Python :: how to remove the last item in a list python 
Python :: Write a python program to find the most frequent word in text file 
Python :: select only some rows pandas 
Python :: django rest framework 
Python :: how to check nth prime in python 
Python :: python reverse linked list 
Python :: how to create table in a database in python 
Python :: pandas check if value in column is in a list 
Python :: how to write a file in python 
Python :: new window selenium python 
Python :: filter list of tuples python 
Python :: linear congruential generator in python 
Python :: how to get decimal part of a double in python 
Python :: print output python to file 
Python :: python get response from url 
Python :: write page source to text file python 
Python :: cut part of video ffmpeg 
Python :: python currency symbol 
Python :: python ssh connection 
Python :: sorting a dictionary by value in python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =