Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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]
 
PREVIOUS NEXT
Tagged: #change #item #list #python
ADD COMMENT
Topic
Name
3+8 =