However, here we know that you're going to have exactly 2 elements in each of those pairs,
a
and
b
. In such situations, you can use a tuple instead. The syntax for Scala's tuples is the same as Python's (
link). You'll notice we no longer need that
mkString
business because all tuple classes have a sane
toString
.
However, you need an extra parentheses in
r += ((a, b))