我知道按长度排序包含单词的列表的列表。 这意味着列表:排序列表中的一组单词
[[],['hello','indent'],['hi','monday'],['hi','low']]
这导致如果排序的关键是长度,情况正好相反:
[['hello','indent','joe'],['hi','monday'],['hi','low'],[]]
但我想要的东西的长度是那种既具有相同长度的那些必须进行排序按字母顺序排列。即,“低” <“星期一”,所以输出应该是:
[['hello','indent','joe'],['hi','low'],['hi','monday'],[]]
我必须使用哪种键的使用内置的排序进行排序?
编辑:但如果输入是混合大小写?如果它是什么:
[['Hi', 'monday'], [], ['hello', 'indent', 'joe'], ['hi', 'low']]
和期望的输出将是:
[['hello', 'indent', 'joe'], ['hi', 'monday'],['Hi', 'low'], []]
你应该使用相同的'的.sort()'它会隐生成期望的输出我猜 – ZdaR 2015-02-10 07:06:49
你可以尝试制作一个自定义函数并将它传递给'key'。 – 2015-02-10 07:08:52