Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change item in list python

#To change elements in list base on a specific condition 
#Using list comprehension
original_list = [1,20,3,40,5]
new_list = ['Do something' if x > 10 else x for x in original_list]

# [1, 'Do something', 3, 'Do something', 5]
Comment

PREVIOUS NEXT
Code Example
Python :: django model choice field from another model 
Python :: image hashing 
Python :: plot histogram from counts and bin edges 
Python :: scrape website with login python selenium 
Python :: python referenced before assignment in function 
Python :: what does enumerate do in python 
Python :: use latest file on aws s3 bucket python 
Python :: django form 
Python :: #index operator in python 
Python :: Check version of package poetry 
Python :: random number generator python 
Python :: convert word to pdf python 
Python :: keras model 2 outputs 
Python :: python sort list opposite 
Python :: pyside click through window 
Python :: free wifi connection disconnects frequently windows 10 
Python :: create sqlite table in python 
Python :: how to specify symbol in matplotlib 
Python :: pandas read csv with lists 
Python :: multiple line string 
Python :: python check if string contains symbols 
Python :: Python | Creating a Pandas dataframe column based on a given condition 
Python :: how to compare list and int in python 
Python :: division of 2 numbers in python 
Python :: net way to print 2d array 
Python :: get parent of current directory python 
Python :: for loop python 
Python :: unique python 
Python :: Implement a binary search of a sorted array of integers Using pseudo-code. 
Python :: how to split a string by space in python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =