我有一个数据集
{6317637: {'name': 'Le Petit Souffle', 'Votes': 314, 'Cuisines': 'French, Japanese, Desserts', 'AverageCostfortwo': 1100, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.8', 'Ratingcolor': 'lightgreen', 'Ratingtext': 'Excellent'}, 6304287: {'name': 'Izakaya Kikufuji', 'Votes': 591, 'Cuisines': 'Japanese', 'AverageCostfortwo': 1200, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.5', 'Ratingcolor': 'lightgreen', 'Ratingtext': 'Excellent'}, 6300002: {'name': 'Heat - Edsa Shangri-La', 'Votes': 270, 'Cuisines': 'Seafood, Asian, Filipino, Indian', 'AverageCostfortwo': 4000, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.4', 'Ratingcolor': 'green', 'Ratingtext': 'Very Good'}, 6318506: {'name': 'Ooma', 'Votes': 365, 'Cuisines': 'Japanese, Sushi', 'AverageCostfortwo': 1500, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'No', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.9', 'Ratingcolor': 'lightgreen', 'Ratingtext': 'Excellent'}, 6314302: {'name': 'Sambo Kojin', 'Votes': 229, 'Cuisines': 'Japanese, Korean', 'AverageCostfortwo': 1500, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.8', 'Ratingcolor': 'lightgreen',
'Ratingtext': 'Excellent'}, 18189371: {'name': 'Din Tai Fung', 'Votes': 336, 'Cuisines': 'Chinese', 'AverageCostfortwo': 1000, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'No', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.4', 'Ratingcolor': 'green', 'Ratingtext': 'Very Good'}, 6300781: {'name': 'Buffet 101', 'Votes': 520, 'Cuisines': 'Asian, European', 'AverageCostfortwo': 2000, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4', 'Ratingcolor': 'green', 'Ratingtext': 'Very Good'}, 6301290: {'name': 'Vikings', 'Votes': 677, 'Cuisines': 'Seafood, Filipino, Asian, European', 'AverageCostfortwo': 2000, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No', 'Aggregaterating': '4.2', 'Ratingcolor': 'green', 'Ratingtext': 'Very Good'}, 6300010: {'name': 'Spiral - Sofitel Philippine Plaza Manila', 'Votes': 621, 'Cuisines': 'European, Asian, Indian', 'AverageCostfortwo': 6000, 'Currency': 'Botswana Pula(P)', 'HasTablebooking': 'Yes', 'HasOnlinedelivery': 'No',
'Aggregaterating': '4.9', 'Ratingcolor': 'lightgreen', 'Ratingtext': 'Excellent'}}
我尝试使用以下代码进行排序:
sorted(frontend_content,key=lambda x:frontend_content[x]['name'])
,但我没有零钱
我该如何根据一个特定的字段排序,比如姓名或投票
在python中不能对
dict
排序,因为它是无序的,所以需要首先将它转换为其他数据类型,如list of list
或list of tuple
通过调用
x.items()
,您将它作为(key,value)
的元组进行迭代。因此,kv[1]
将是这里的值相关问题 更多 >
编程相关推荐