for i in range(0, len(match_parts)):
    if match_parts[i] in dictionary and dictionary[match_parts[i]] != False:
        if replace_func is not None:
            result.append(replace_func(match_original[i], dictionary[
                match_parts[i]]))
else:
    result.append(dictionary[match_parts[i]])
result.append(word)
last_match = ''
original = ''
return ' '.join(result)
Python dictionary replacement with space in key