想问问大家这个问题怎么解决☺️☺️真的做不出来

英语文本如下
What is a function in Python? In Python, function is a group of related statements that perform a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes code reusable. A function definition consists of following components. Keyword def marks the start of function header. A function name to uniquely identify it. Function naming follows the same rules of writing identifiers in Python. Parameters (arguments) through which we pass values to a function. They are optional. A colon (:) to mark the end of function header. Optional documentation string (docstring) to describe what the function does. One or more valid Python statements that make up the function body. Statements must have same indentation level (usually 4 spaces). An optional return statement to return a value from the function.

img


import re
source = '''What is a function in Python? In Python, function is a group of related statements that perform a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes code reusable. A function definition consists of following components. Keyword def marks the start of function header. A function name to uniquely identify it. Function naming follows the same rules of writing identifiers in Python. Parameters (arguments) through which we pass values to a function. They are optional. A colon (:) to mark the end of function header. Optional documentation string (docstring) to describe what the function does. One or more valid Python statements that make up the function body. Statements must have same indentation level (usually 4 spaces). An optional return statement to return a value from the function.'''

def convert(s):
    return re.sub(r'[^a-zA-Z]',' ',s)
def count(s):
    arr = s.split()
    return {word:arr.count(word) for word in set(arr)}
target = count(convert(source))
print(*[k + ':' + str(target[k]) for k in sorted(target,key = lambda x:-target[x]) if k not in ['of','a','the','an','in']][:10],sep='\n')

import string

text = "What is a function in Python? In Python, function is a group of related statements that perform a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes code reusable. A function definition consists of following components. Keyword def marks the start of function header. A function name to uniquely identify it. Function naming follows the same rules of writing identifiers in Python. Parameters (arguments) through which we pass values to a function. They are optional. A colon (:) to mark the end of function header. Optional documentation string (docstring) to describe what the function does. One or more valid Python statements that make up the function body. Statements must have same indentation level (usually 4 spaces). An optional return statement to return a value from the function."
text = text.translate(str.maketrans("", "", string.punctuation))
text = ''.join([i for i in text if not i.isdigit()])
words = text.lower().split()
excluded_words = ["of", "the", "and", "in", "a"]
word_counts = {}
for word in words:
    if word not in excluded_words and word.isalpha():
        if word not in word_counts:
            word_counts[word] = 1
        else:
            word_counts[word] += 1
sorted_word_counts = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)
for i in range(10):
    print(f"{sorted_word_counts[i][0]}: {sorted_word_counts[i][1]}")