I have a list like this ['BASE', 'BASE xBU xPY', 'BU GROUP REL', 'PY REL']
and I want to convert it to ['BASE', 'BASE_xBU_xPY', 'BU_GROU_ REL', 'PY_REL']
in short convert space to underscore for value in b/w quotes
Asked
Active
Viewed 2,600 times
0
-
1Okay, so what prevents you from doing it? – Karl Knechtel Oct 16 '20 at 06:58
1 Answers
4
I would suggest using replace
along with map
Example:
my_list = ['BASE', 'BASE xBU xPY', 'BU GROUP REL', 'PY REL']
converter = lambda x: x.replace(' ', '_')
my_list = list(map(converter, my_list))
my_list
['BASE', 'BASE_xBU_xPY', 'BU_GROUP_REL', 'PY_REL']

Kuldeep Singh Sidhu
- 3,748
- 2
- 12
- 22