Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从何处开始:Python脚本,允许用户通过比较对元素进行排序_Python_Sorting - Fatal编程技术网

从何处开始:Python脚本,允许用户通过比较对元素进行排序

从何处开始:Python脚本,允许用户通过比较对元素进行排序,python,sorting,Python,Sorting,在我工作的地方,我们会对候选人进行复评。我希望在审查时尽可能公平,但我忍不住觉得,我只是把每一份简历与脑海中任意的一份进行排序,看看我面前的那份简历与我的理想有多接近 为了解决这个问题,我正在尝试编写一个 1) 向用户显示两份简历 2) 用户选择哪个更好 3) 程序说,“这份简历在排名上总是高于其他简历” 4) 重复步骤1-3 5) 最终,每一份简历都被分类到大致正确的位置(不必100%完美),然后审查继续进行 希望这能消除系统中的一些偏见,使简历审查更公平。我相信这是我们都想要的 我的问题是我

在我工作的地方,我们会对候选人进行复评。我希望在审查时尽可能公平,但我忍不住觉得,我只是把每一份简历与脑海中任意的一份进行排序,看看我面前的那份简历与我的理想有多接近

为了解决这个问题,我正在尝试编写一个

1) 向用户显示两份简历

2) 用户选择哪个更好

3) 程序说,“这份简历在排名上总是高于其他简历”

4) 重复步骤1-3

5) 最终,每一份简历都被分类到大致正确的位置(不必100%完美),然后审查继续进行

希望这能消除系统中的一些偏见,使简历审查更公平。我相信这是我们都想要的

我的问题是我不知道从哪里开始。我可能没有使用正确的搜索词,但每当我查找“如何使用python手动排序”或“选择一个元素并在python中排序”时,都没有真正的结果

我现在并不担心界面部分:我只想在后端开始运行,以便以后添加UI

至于我在Python方面的背景,我已经掌握了基础知识,我可以学习任何我需要学习的东西(我做过套利编码、硒元素、刮片和各种生物信息学的东西)。称之为中间编码器的开始阶段


谢谢你的帮助

关于如何实现这一点,您有很多选择,但我认为基本上您需要实现一个排序算法,用户在其中对项目进行比较

下面是一个冒泡排序的示例,它很容易实现,但不是最优的。选择合并排序将最大限度地减少用户必须进行的比较次数

def bubble_sort_resumes(resume_list):
    n = len(resume_list)
    for i in range(n):
        for j in range(n-i-1):
            if user_decides_if_the_first_resume_is_better(resume_list[j], resume_list[j+1]):
                resume_list[j], resume_list[j+1] = resume_list[j+1], resume_list[j]

def user_decides_if_the_first_resume_is_better(resume1, resume2):
    # todo: implement me
    # return True if resume1 is better, False if resume2 is better
我并不特别推荐你选择冒泡排序而不是其他排序算法,这很简单

这里还有一个基本假设,即简历可以被评估为一个单一的变量,这可能不是真的——人们可能在某些方面有优势,而在其他方面有弱点。但听起来你很乐意做出简单的假设


您可能遇到的一个问题是,如果用户说(或会说):resume 1优于2,resume 2优于3,resume 3优于1,则不清楚该如何处理该案例。

您有很多选择,可以选择如何实现该目标,但我认为基本上你需要实现一个排序算法,用户在其中对项目进行比较

下面是一个冒泡排序的示例,它很容易实现,但不是最优的。选择合并排序将最大限度地减少用户必须进行的比较次数

def bubble_sort_resumes(resume_list):
    n = len(resume_list)
    for i in range(n):
        for j in range(n-i-1):
            if user_decides_if_the_first_resume_is_better(resume_list[j], resume_list[j+1]):
                resume_list[j], resume_list[j+1] = resume_list[j+1], resume_list[j]

def user_decides_if_the_first_resume_is_better(resume1, resume2):
    # todo: implement me
    # return True if resume1 is better, False if resume2 is better
我并不特别推荐你选择冒泡排序而不是其他排序算法,这很简单

这里还有一个基本假设,即简历可以被评估为一个单一的变量,这可能不是真的——人们可能在某些方面有优势,而在其他方面有弱点。但听起来你很乐意做出简单的假设


你可能遇到的一个问题是,如果用户说(或会说):简历1比2好,简历2比3好,简历3比1好,你不清楚该如何处理这个问题。

我认为你需要一个软件来拥有投票系统,这样它可以计算你选择简历的次数字典是最好的工具

假设我在一个文件夹中有3份简历。简历的标题从1.pdf到3.pdf

1-使用
os.listdir(“PATH/TO/FOLDER/)
这将在列表中列出你简历的所有标题

2-将列表转换为字典。字典键将是简历标题,开始时其值将为0。最终,这些值将反映每个简历收到的投票数

3-创建一个嵌套for循环,以相互比较简历

4-每当用户选择一份简历而不是另一份简历时,简历的值将增加1

#resumes = os.list(Path/To/Folder)

resumes = ["1.pdf","2.pdf", "3.pdf"]

resumeDictionary = { i : 0 for i in resumes } #Convert list to dictionary and give all keys a value 0

resumeRecord=[] #List to keep a record of resume comparison combinations

for resume in resumes:
    for Anotherresume in resumes:
        if Anotherresume is resume or [resume,Anotherresume] in resumeRecord or [Anotherresume,resume] in resumeRecord: #Prevent duplicate/repeated resume comparisons
            continue
        userInput = input("Which resume do you prefer? Press 1 or 2\n[1] " + resume + "\n" + "[2] " + Anotherresume + "\n")
        if int(userInput) == 1:
            resumeDictionary[resume] += 1
        elif int(userInput) == 2:
            resumeDictionary[Anotherresume] += 1
        resumeRecord.append([resume,Anotherresume]) #Record combination

print(resumeDictionary)
如果我运行上面的代码并选择resume“1.pdf”三次,我最终会得到一本这样的字典

{'1.pdf': 3, '2.pdf': 1, '3.pdf': 2}

我认为你需要有一个投票系统的软件,这样它可以计算你选择简历的次数。字典是最好的工具

假设我的文件夹中有3份简历,标题从1.pdf到3.pdf

1-使用
os.listdir(“PATH/TO/FOLDER/)
这将在列表中列出你简历的所有标题

2-将列表转换为字典。字典键将是简历标题,开始时它们的值将是0。最终,这些值将决定每份简历获得的票数

3-创建一个嵌套for循环,以相互比较简历

4-每当用户选择一份简历而不是另一份简历时,简历的值将增加1

#resumes = os.list(Path/To/Folder)

resumes = ["1.pdf","2.pdf", "3.pdf"]

resumeDictionary = { i : 0 for i in resumes } #Convert list to dictionary and give all keys a value 0

resumeRecord=[] #List to keep a record of resume comparison combinations

for resume in resumes:
    for Anotherresume in resumes:
        if Anotherresume is resume or [resume,Anotherresume] in resumeRecord or [Anotherresume,resume] in resumeRecord: #Prevent duplicate/repeated resume comparisons
            continue
        userInput = input("Which resume do you prefer? Press 1 or 2\n[1] " + resume + "\n" + "[2] " + Anotherresume + "\n")
        if int(userInput) == 1:
            resumeDictionary[resume] += 1
        elif int(userInput) == 2:
            resumeDictionary[Anotherresume] += 1
        resumeRecord.append([resume,Anotherresume]) #Record combination

print(resumeDictionary)
如果我运行上面的代码并选择resume“1.pdf”三次,我最终会得到一本这样的字典

{'1.pdf': 3, '2.pdf': 1, '3.pdf': 2}

当您说“显示2份简历”时,您是否选择要比较的简历?或者它们是通过编程选择的?@egragoth它们将通过编程选择。当您说“显示2份简历”时,您是否选择要比较的简历?或者它们是通过编程方式选择的?@agragoth它们将通过编程方式选择。在实现中,您将对每个值进行两次比较,而且还不清楚为什么“字典是用于此目的的最佳工具”,感谢您指出:),我修复了代码。关于字典,因为字典的整体思想是将一组数据链接到另一组数据,这适用于旨在存储简历及其投票计数的应用程序。这使得修改/查找字典键比其他非基本da更容易