Home > Software engineering >  How remove parts of a value in each value of a list?
How remove parts of a value in each value of a list?

Time:10-12

I have this list:

original_list = ['1 b Victor','1 b Pedro','1 b Laura','1 b Maria']

I want to remove "1 b" from each value of the list and reach this example list:

final_result = ['Victor', 'Pedro', 'Laura', 'Maria']

How can I do this?

CodePudding user response:

Call str.replace() in a list comprehension.

final_result = [s.replace('1 b ', '') for s in original_list]
  • Related