Scala 元组列表到平面列表 [英] Scala List of tuples to flat list
本文介绍了Scala 元组列表到平面列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有元组对列表 List[(String,String)]
并且想将其展平为字符串列表 List[String]
.>
I have list of tuple pairs, List[(String,String)]
and want to flatten it to a list of strings, List[String]
.
推荐答案
一些选项可能是:连接:
Some of the options might be: concatenate:
list.map(t => t._1 + t._2)
一个接一个地交错(在您发表评论之后,您似乎要求这样做):
one after the other interleaved (after your comment it seems you were asking for this):
list.flatMap(t => List(t._1, t._2))
拆分并附加它们:
list.map(_._1) ++ list.map(_._2)
这篇关于Scala 元组列表到平面列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文