There are two practical ways to square each element of a list, and return the new list. For example, if we input a List(5, 10), we should have a List(25, 100). Method 1: Pattern Matching def squareList(xs: List[Int]): List[Int] = xs match { case Nil => xs case y :: ys => y * y :: squareList(ys) } If xs is empty, case Nil will trigger, simply returning the list that was passed in to squareList.
0 CommentsThere are a few ways to search for a string in Python (3+): String operations str.find(sub[, start[, end]])] "shadow walker".find('w') => 5 This gives you the index of the first match. While the index might be nice to have, do remember that strings are immutable.
0 CommentsUse Cases There are many ways to store your data. In this article we'll walk through some examples of data storage in common system designs. Reminder: There is no single best storage choice and they may vary heavily depending on things such as access patterns and scale.
0 Comments