我有一个字数示例。如果我想过滤出一个常见的单词,我可以这样做,其中wordList是一个元组:
val filterWords = wordList.filter(x => x != "to")
但是创建要过滤的单词列表更有用:
val filterWords = ("a", "to", "the", "of", "I", "you")
如何在上面的过滤器中使用它?或者,我该怎么做呢(用SQL完成)?
where wordList not in ("a", "to", "the", "of", "I", "you")
答案 0 :(得分:2)
CombinedEventDirective
val filterWords = Set("a", "to", "the", "of", "I", "you")
wordList.filterNot(filterWords.contains(_))
将仅在考虑中的filterWords.contains
元素在wordList
中时返回true。 filterWords
将通过filterNot
调用为其返回false的元素。
答案 1 :(得分:0)
您创建的是元组而不是列表。
MacBook-Pro:CommandLineTools myname$ ls
Library SDKs usr
然后您就可以使用
val filterWords = List("a", "to", "the", "of", "I", "you")
还可以查看完整的api of List