How do I find the index of an element in a Scala list.
val ls = List(\"Mary\", \"had\", \"a\", \"little\", \"lamb\")
I need to get 3 if I ask f
If you want list of all indices containing "a", then:
val ls = List("Mary", "had", "a", "little", "lamb","a") scala> ls.zipWithIndex.filter(_._1 == "a").map(_._2) res13: List[Int] = List(2, 5)