Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

replace multiple elements in a list python

mapping = {
    '1': 'i',
    '2': 'put',
    '3': 'this',
    '4': 'here',
}
sentence = ['1', '2', '3', '4']
newsentence = [mapping.get(word, word) for word in sentence]
# ['I', 'put', 'this', 'here']
 
PREVIOUS NEXT
Tagged: #replace #multiple #elements #list #python
ADD COMMENT
Topic
Name
1+7 =