基本上,我首先将字典放入列表中,然后在该列表中取出 6 个键。我还让用户输入一些值。现在我想把键和值放回另一个字典。
我试过把它放在普通的字典格式中,例如:
eliminate1 = {newcouple1:Couple01,newcouple2:Couple02,newcouple3:Couple03,newcouple4:Couple04}
import operator
from operator import itemgetter
eliminate1 = {newcouple1:Couple01,newcouple2:Couple02,newcouple3:Couple03,newcouple4:Couple04}
sorted_eliminate1 = sorted(eliminate1.items(), key=operator.itemgetter(1))
gone = print("These Couples have been eliminated: ",dict(sorted_eliminate[0:2]))
gone1 = dict(sorted_eliminate1[0:2])
remaining01 = print("These are the remaining couples: ",dict(sorted(eliminate1.items(), key = itemgetter(1))[2:]))
remaining1 = dict(sorted(eliminate1.items(), key = itemgetter(1))[2:])
运行代码时出现错误:
eliminate1 = {newcouple1:Couple01,newcouple2:Couple02,newcouple3:Couple03,newcouple4:Couple04}
这是错误: TypeError: unhashable type: 'list'
慕娘9325324
红颜莎娜
相关分类