这节课不听 2023-01-08 21:37 采纳率: 60%
浏览 19
已结题

集合排列组合的长度为什么是0

为什么集合的排列组合的结果长度为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

  • 写回答

1条回答 默认 最新

  • 这节课不听 2023-01-08 22:01
    关注

    想明白,傻b了,迭代器不可以重复遍历.

    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月16日
  • 创建了问题 1月8日

悬赏问题

  • ¥15 如何用MATLAB写一段烟幕弹拦截导弹的代码?
  • ¥15 这两个验证谁能解决,带价来
  • ¥15 matlab可视化全球TEC含量图
  • ¥15 怎么将普通C++转入UE5
  • ¥15 求一段多输入类型的matlab lstm的代码
  • ¥15 零基础200题编字典问题
  • ¥15 win11移除微软账户登录
  • ¥15 部署zabbix登录时跳转如下页面
  • ¥15 cup+fpga+88E1111 rgmii to sgmii
  • ¥15 请问如何从gprmax中导出的merged.out文件获取雷达数据(应该是个二维数组吧),我看到网上很多对雷达数据的操作但是都没有说如何获得这个数据,因为out文件不能直接操作要转成其他格式是吧