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 :: at=error code=H10 desc="App crashed" django 
Python :: python telegram bot 
Python :: how to create an array in python 
Python :: python regex search file 
Python :: get tweet by its id 
Python :: map example in python 
Python :: import class in python 
Python :: python list add first 
Python :: python openpyxl cell width 
Python :: drop row with condition dataframe 
Python :: pygame mixer documentation 
Python :: python strptime() 
Python :: how to make an int into a string python 
Python :: print with no newline 
Python :: quick sort python 
Python :: trim string python 
Python :: Python NumPy repeat Function Example 
Python :: how to get a dictionary in alphabetical order python 
Python :: get dictionary values python 
Python :: Adding labels to histogram bars in matplotlib 
Python :: How To Get Redirection URL In Python 
Python :: sharpdevelop pause python code 
Python :: how to make a loading gif in pyqt5 
Python :: one hot numpy 
Python :: remove unnamed columns pandas 
Python :: transform data frame in list 
Python :: pandas loc condition 
Python :: python define class 
Python :: python match statement 
Python :: logging 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =