import re

regex_whitespace = r'(\w+)\s+(\w+)\b'
pattern = re.compile(regex_whitespace) # this I just added after reviewing other related questions
labels_ls = ['word <= 0.01', 'word_two <= 0.23', 'word three <= 0.01']
# Loop through labels_ls to find any ngrams whitespace separated labels (i.e gilt maximal)
for i in labels_ls:
    if re.match(regex_whitespace, i):
        # replace the whitespace with a '_' to form gilt*maximal
        new_string = re.sub(pattern, r'\1_\2', i)
        print('new string: ', new_string)