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

replace list python

# 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 :: join multiple excel files with python 
Python :: what is django python 
Python :: python version of settimout 
Python :: how to import data in python 
Python :: copy python 
Python :: how to implement dfa in python 
Python :: issubclass python example 
Python :: precision accuracy recall python example 
Python :: pandas get size of each group 
Python :: add header info in django response 
Python :: reaction role discord.py 
Python :: pandas filter 
Python :: how to sort numpy array 
Python :: change the format of date in python 
Python :: oop in python 
Python :: python find length of list 
Python :: os.path.join 
Python :: manytomany django add bulk create 
Python :: django pytest how to load data 
Python :: variable python 
Python :: variables in python 
Python :: download gzip file python 
Python :: how to run other python files in python 
Python :: aws s3 sync boto3 
Python :: how to use str() 
Python :: pandas sort by list 
Python :: pandas drop rows 
Python :: comparison python 
Python :: python create a global variable 
Python :: Show all column names and indexes dataframe python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =