我有一本包含以下信息的词典:
my_dict = {
'key1' : ['f', 'g', 'h', 'i', 'j'],
'key2' : ['b', 'a', 'e', 'f', 'k'],
'key3' : ['a', 'd', 'c' , 't', 'z'],
'key4' : ['a', 'b', 'c', 'd', 'e']
}
我想知道如何使用列表的索引0按字母顺序对打印结果排序。如果两个列表的索引0相同,则在排序时将考虑下一个索引,即索引1
输出应如下所示:
Officer 'a', 'b' with 'key4' ate 'c' with 'd' and 'e'.
Officer 'a', 'd' with 'key3' ate 'c' with 't' and 'z'.
Officer 'b', 'a' with 'key2' ate 'e' with 'f' and 'k'.
Officer 'f', 'g' with 'key1' ate 'h' with 'i' and 'j'.
只需对dictionary items按值排序即可:
相关问题 更多 >
编程相关推荐