小编Pra*_*wol的帖子

如何以创建多个函数但不必一次又一次编写相同代码的方式编写代码?

我让所有这些函数都执行类似的任务。如何编写代码以创建所有这些函数,但不必一次又一次地编写相同的代码?

def get_civilservice_result(user_skill_string): 
    civilservice_keyword = firestore.client().collection('keyword').document('civilservice').get().to_dict()['key']
    civilservice_keyword_string = ' '.join(str(e) for e in civilservice_keyword)
    result = get_result(user_skill_string, civilservice_keyword_string)
    return result


def get_education_result(user_skill_string): 
    education_keyword = firestore.client().collection('keyword').document('education').get().to_dict()['key']
    education_keyword_string = ' '.join(str(e) for e in education_keyword)
    result = get_result(user_skill_string, education_keyword_string)
    return result

    
def get_engineering_result(user_skill_string): 
    engineering_keyword = firestore.client().collection('keyword').document('engineering').get().to_dict()['key']
    engineering_keyword_string = ' '.join(str(e) for e in engineering_keyword)
    result = get_result(user_skill_string, engineering_keyword_string)
    return result
Run Code Online (Sandbox Code Playgroud)

python function

2
推荐指数
1
解决办法
129
查看次数

标签 统计

function ×1

python ×1