replace multiple elements in a list python

Solutions on MaxInterview for replace multiple elements in a list python by the best coders in the world

showing results for - "replace multiple elements in a list python"
Paul
21 Jan 2020
1mapping = {
2    '1': 'i',
3    '2': 'put',
4    '3': 'this',
5    '4': 'here',
6}
7sentence = ['1', '2', '3', '4']
8newsentence = [mapping.get(word, word) for word in sentence]
9# ['I', 'put', 'this', 'here']