Finding character in 2 dimensional scala list -
so might not best way tackle initial thought expression. have list like
list(list('a','b','c'),list('d','e','f'),list('h','i','j'))
i find row , column character, 'e'
.
def findchar(letter: char, list: list[list[char]]): (int, int) = { r <- (0 until list.length) c <- (0 until list(r).length) if list(r)(c) == letter } yield (r, c)
if there more elegant way i'm ears understand what's wrong this. error compiler gives me here
type mismatch; found : scala.collection.immutable.indexedseq[(int, int)] required: (int, int)
on line assigning r
. seems complaining iterator doesn't match return type don't quite understand why or ...
for other ear, question duplicates
how capture inner matched value in indexwhere vector expression?
scala> list(list('a','b','c'),list('d','e','f'),list('h','i','j')) res0: list[list[char]] = list(list(a, b, c), list(d, e, f), list(h, i, j)) scala> .map(_ indexof 'e').zipwithindex.find(_._1 > -1) res1: option[(int, int)] = some((1,1))
Comments
Post a Comment