gpt4 book ai didi

scala - List[(Int,Int)] Into List[Int] - 求教

转载 作者:行者123 更新时间:2023-12-02 05:48:11 26 4
gpt4 key购买 nike

好的,所以我已经搜索了大约一个小时,找不到任何实际的方法来获取元组整数列表 I.Eval e = List((5,10),(10,13),(30,37))在不使用可变列表的情况下,我想根据旧列表创建一个新列表……但是在这个新列表而不是元组中,我想要两个值之间的所有整数。I.E 上面的 LIST 到 => List(6,7,8,9,11,12,31,32,33,34,35,36)

如有任何帮助,我们将不胜感激。

TL:DR List of Tuples[Int,Int] into new List of values inbetween the two into ints untupled.

最佳答案

scala> val e = List((5,10),(10,13),(30,37))
e: List[(Int, Int)] = List((5,10), (10,13), (30,37))

scala> e.flatMap(t => t._1+1 until t._2)
res1: List[Int] = List(6, 7, 8, 9, 11, 12, 31, 32, 33, 34, 35, 36)

关于scala - List[(Int,Int)] Into List[Int] - 求教,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40866981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com