【发布时间】:2019-09-14 19:40:00
【问题描述】:
我有这个列表的字典
Dict = {'Language': ['german', 'hindi', 'arabic', 'spanish'], 'Auto': ['porsche', 'bmw', 'jaguar', 'chrysler'], 'Mobile': ['nokia', 'apple', 'asus', 'samsung']}
在按值对字典进行排序后,我希望 o/p 为:
{'Language': ['arabic', 'german', 'hindi', 'spanish'], 'Auto': ['bmw', 'chrysler', 'jaguar', 'porsche'], 'Mobile': ['apple', 'asus', 'nokia', 'samsung']}
所有列表元素按字母顺序排序。我尝试在 sorted 函数中使用 lambda 函数,但它不起作用。因此,有人可以看看并纠正我的一小段代码..
sorted(Dict.items(), key = lambda t: t[1][0])
【问题讨论】:
标签: python python-3.x