0

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

yatu
  • 86,083
  • 12
  • 84
  • 139
asriva
  • 33
  • 1
  • 2

1 Answers1

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