File size: 757 Bytes
62bf5f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def compare_text(text_to_guess, text_to_match):
    words_to_match = text_to_match.lower().split(" ")
    words_to_guess = text_to_guess.strip().split(" ")
    return [
        [word, word.lower() in words_to_match, i < len(words_to_match) and word.lower() == words_to_match[i]] for i, word in enumerate(words_to_guess) 
    ]

def format_one_word(word, in_sentence, correct_place):
    if in_sentence and correct_place:
        return f"**:green[{word}]**"
    elif in_sentence:
        return f"**:gray[{word}]**"
    else:
        return f"**:red[{word}]**"
    
def format_text_html(compare_text_dict):
    return " ".join([
        format_one_word(word, in_sentence, correct_place)  for word, in_sentence, correct_place in compare_text_dict
        ])