为什么集合的排列组合的结果长度为0
scala代码
import scala.collection.immutable
object Test {
def main(args: Array[String]): Unit = {
val a=1 to 3
val b: Iterator[immutable.IndexedSeq[Int]] = a.permutations
println(b.mkString(","))
println(b.count(x=>true))
val c: Iterator[immutable.IndexedSeq[Int]] = a.combinations(2)
println(c.mkString(","))
println(c.count(x => true))
}
}
执行结果
Vector(1, 2, 3),Vector(1, 3, 2),Vector(2, 1, 3),Vector(2, 3, 1),Vector(3, 1, 2),Vector(3, 2, 1)
0
Vector(1, 2),Vector(1, 3),Vector(2, 3)
0
python代码
import itertools
if __name__ == '__main__':
a=range(1,4)
b=itertools.permutations(a)
print(list(b))
print(len(list(b)))
c=itertools.combinations(a,2)
print(list(c))
print(len(list(c)))
执行结果
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
0
[(1, 2), (1, 3), (2, 3)]
0