Exercise 2 in scala

Get number of constituencies by state sorted in descending order by number of constituencies

I am able to get the first two columns : state and constituency
Next how to approach with groupBy

I tried like this
val z=results.map(s => (s.split("\t")(0),s.split("\t")(1)))
z.groupBy(o => o.state)

Please let me know the soluntion to this

@soumalya - Could you please paste the full code?

:paste

import scala.io.Source
val a=“ls2014.tsv"
val results=Source.fromFile(a).getLines
val z=results.map(s => (s.split(”\t")(0),s.split("\t")(1)))
val y=z.toList
val x=y.groupBy(rec => rec._1)
val w=x.map(m => (m._1,m._2.size))
w.toList.sortBy(rec => -rec._2)

Could you please validate this…

@soumalya

val byConsandstate = results.map(rec => ((rec.split("\t")(1), rec.split("\t")(0)), rec.split("\t")(10).toInt)).toList

Get number of constituencies by state sorted in descending order by number of constituencies–here it is mentioned no of constituencies not number of votes.

Could you please confirm my understanding.

@soumalya - You refer your results in another topic.