该程序的基本要点是从员工姓名列表开始,然后对其进行排序。等待用户输入“end”以停止填充名称列表(我有 100 个名称,我将其缩短为示例)。之后,用户可以输入员工姓名,程序将运行 difflib.get_close_matches()。
这是问题;我收到 get_close_matches 的语法错误。我应该如何以不同的方式进入 difflib?还; 如果您有任何使代码更高效的提示,请同时说明它如何以及为什么更高效。我对 Python 相当缺乏经验,所以要温柔,嗯?
示例代码:
import difflib
employeeNames = ['Colton','Jayne','Barb','Carlene','Dick','Despina']
employeeNames.sort()
endInput = input('Type "end" to view list of names.\n\n')
if endInput == "end":
userEmpName = input("Please enter the employee name you're searching for. We'll return the best match on record."
get_close_matches(userEmpName, employeeNames, 1)