是否可以相对于彼此对字符串元素列表进行排序?

Is it possible to sort lists of string elements, with respect to each other?

假设我有他下面的列表列表 = [[1, ["test"]], [2, ["array", "new", ]], [3, ["apple]], [4,["balls"]]]

如何最有效地对该列表进行排序,以便包含字符串的最内层列表按相似长度和字母顺序分组,并假设内部字符串列表已按字母顺序排序。就像是; [[3, ["apple], [4,["balls"], [1, ["test"], [2, ["array", "new"]]

我正在考虑使用基数排序,但我不确定如何调用基数排序来比较多个列表

l =  [[1, ["test"]], [2, ["array", "new"]], [3, ["apple"]], [4,["balls"]]]
print(sorted(l,key=lambda l:(len(l[1]),l[1])))

输出

[[3, ['apple']], [4, ['balls']], [1, ['test']], [2, ['array', 'new']]]

python

中函数的复杂性

https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt