带有2个for循环的列表推导给出了太多的值而无法解压

时间:2018-06-28 07:06:08

标签: python python-3.x list-comprehension

我正在运用2个列表理解来做我的工作

actual_skill_list = [process.extractOne(skill, lookup_skill_dict.get(skill.lower()[0], set()), scorer=fuzz.QRatio)for skill in skill_list]
actual_skill_list = [x for x, y in actual_skill_list if y > 80]

process.extractOne返回2值-匹配及其得分,例如("dkjbdsk", 80)

我正在尝试将上述两个列表理解合并为一个。我尝试这样做-

actual_skill_list = [x for skill in skill_list for x, y in process.extractOne(
            skill, lookup_skill_dict.get(skill.lower()[0], set()), scorer=fuzz.QRatio)  if y >= 80]

它给予-Traceback: <class 'ValueError'>: too many values to unpack (expected 2)

我不确定自己在做什么错

1 个答案:

答案 0 :(得分:1)

您缺少列表括号:

actual_skill_list = [x for skill in skill_list for x, y in 
[process.extractOne(
            skill, lookup_skill_dict.get(skill.lower()[0], set()), 
scorer=fuzz.QRatio)]  if y >= 80]