Zachary Lyness
Zachary Lyness

Reputation: 11

Finding elements in a list of strings that contain integers

I have a list of strings, of which I need to find the last string in the list that has an integer in it, and make a new list of strings of that element and every element following. So if I had (a,b,c2,d,e3,f) I would need to grab e3, and f. .

Not sure how to do this. my first idea is to reverse the order of the list that way I only need to find the first element that has an integer but im still having trouble

    def Rhyme(soundlis1: List[String]): Unit ={
    var revlist : List[String] = soundlis1.reverse
    }

this is pretty much what i've got, ive tried all sorts of loops but haven't seemed to have gotten one to work yet, not sure if loops just work differently than what im used to or what.

Upvotes: 1

Views: 107

Answers (1)

jwvh
jwvh

Reputation: 51271

val result = soundlis1.drop(soundlis1.lastIndexWhere(_.exists(_.isDigit)))

Upvotes: 2

Related Questions