Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays KOTLIN比较n维数组_Arrays_List_Sorting_Kotlin - Fatal编程技术网

Arrays KOTLIN比较n维数组

Arrays KOTLIN比较n维数组,arrays,list,sorting,kotlin,Arrays,List,Sorting,Kotlin,我需要对列表的列表进行排序。。。 我在python中有类似的内容: a = sorted([[[1,2],[3,4]],[[1]]]) 科特林有类似的东西吗? 我发现定制的comparator对象对于这样一个简单的任务来说确实令人困惑。如果我正确理解Python sorted()方法,这应该会产生相同的行为: fun main() { val a = listOf(listOf(listOf(1,2),listOf(4,3)), listOf(listOf(0,2,1)),listOf

我需要对列表的列表进行排序。。。 我在python中有类似的内容:

a = sorted([[[1,2],[3,4]],[[1]]])
科特林有类似的东西吗?
我发现定制的comparator对象对于这样一个简单的任务来说确实令人困惑。

如果我正确理解Python sorted()方法,这应该会产生相同的行为:

fun main() {
    val a = listOf(listOf(listOf(1,2),listOf(4,3)), listOf(listOf(0,2,1)),listOf(listOf(1)))
    val b =a.sortedBy {it -> it.size}
    println(a)
    println(b)
}
输出:

[[[1, 2], [4, 3]], [[0, 2, 1]], [[1]]]
[[[0, 2, 1]], [[1]], [[1, 2], [4, 3]]]
[[[1, 2], [4, 3]], [[0, 2, 1]], [[1]]]
[[[0, 2, 1]], [[1]], [[1, 2], [4, 3]]]
Python等价物:

a = [[[1,2],[4,3]], [[0,2,1]] ,[[1]]]
b = sorted(a)
print(a)
print(b)
输出:

[[[1, 2], [4, 3]], [[0, 2, 1]], [[1]]]
[[[0, 2, 1]], [[1]], [[1, 2], [4, 3]]]
[[[1, 2], [4, 3]], [[0, 2, 1]], [[1]]]
[[[0, 2, 1]], [[1]], [[1, 2], [4, 3]]]