Hi all I've got and input strings:
list_of_strings = ["apple", "orange ca", "pear sa", "banana sth"]
And I want to remove everything after multiple white spaces (more than 1), so end result is:
final_list_of_strings = ["apple", "orange ca", "pear", "banana"]
I've tried regex:
import re
regex_expression = r"(.*\s?)(\s{2,}.*)"
for name in list_of_strings:
regex_matching_groups = re.findall(regex_expression, name)
if regex_matching_groups:
name = regex_matching_groups[0][0]
but fails on multiple spaces ... Thank you for help!