题目链接:500. 键盘行
from typing import List
class Solution:
@staticmethod
def is_inside(word: str, line: str) -> bool:
return len(set(word).difference(set(line))) == 0
def is_inside_one_line(self, word: str) -> bool:
return self.is_inside(word.lower(), 'qwertyuiop') \
or self.is_inside(word.lower(), 'asdfghjkl') \
or self.is_inside(word.lower(), 'zxcvbnm')
def findWords(self, words: List[str]) -> List[str]:
return list(filter(self.is_inside_one_line, words))