gpt4 book ai didi

python - 有没有办法从个人列表中找到最佳个人,然后将其附加到列表中?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:20:45 25 4
gpt4 key购买 nike

我正在建立一个列表,其中我有几个具有编程技能和他们的工作率的人。我目前处于困境,因为我正试图根据每美元所涵盖的技能从该列表中大致找到最佳人选。我应该使用什么算法来评估孤立的个体?

我一直试图让 for 循环迭代,但它没有移动位置。它在只查看第一个单元格后结束。

jess = (["php", "java"], 200)

clark = (["php", "c++", "go"], 1000)

john = (["lua"], 500)

cindy = (["php", "go", "word"], 240)

candidates = [jess, clark, john, cindy]

project = ["php", "java", "c++", "lua", "go"]

def team_of_best_individuals(project, candidates):

##note that in the list candidates, I tried to divide the number of items in the tuple by the cost, in order to find the skill per dollar

def team_of_best_individuals(project, candidates):
skillList = []
for name in (candidates):
len(name)
for skill in name[0]:
skillList.append(skill)

if len(skillList) == len(name):
num_of_skills=len(skillList)
cost = name[1]
num_skill_per_dollar = num_of_skills/cost
return num_skill_per_dollar, candidates[0:4]
print("skill per dollar="+str(team_of_best_individuals(project, candidates)))

预期(产出)必须是每美元涵盖最多技能的人。返回值必须是列表中人的位置整数。

例如

0 - 4

最佳答案

漂亮优雅的回答@Mark Meyer,我想在这里补充一点,我认为您的问题中缺少这一点。它需要寻找作为项目一部分的技能。如果候选人拥有的任何技能不属于此,则必须打折。我试着写一些可以做到这一点的东西。正如他所指出的,单独使用候选名称而不是变量名称可能是值得的。

jess = (["php", "java"], 200)

clark = (["php", "c++", "go"], 1000)

john = (["lua"], 500)

cindy = (["php", "go", "word"], 240)

candidates = [jess, clark, john, cindy]

project = ["php", "java", "c++", "lua", "go"]

def team_of_best_individuals(project, candidates):
best = ('A', 0)
for ind, candidate in enumerate(candidates):
skills = candidate[0]
skillperdollar = len([skill for skill in skills if skill in project])/candidate[1]
if skillperdollar > best[1]:
best = (ind, skillperdollar)
return best

关于python - 有没有办法从个人列表中找到最佳个人,然后将其附加到列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56142113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com