Answers for "replace multiple elements in a list python"

0

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']
Posted by: Guest on August-03-2021

Code answers related to "replace multiple elements in a list python"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language