I am working on a Leetcode test about keyboard rows, and I don't know the exactly meaning of that(actually I can't run it correctly in pycharm)I don't know why use list[str] can't confirm the type you input is string,and the IDE always pop the error,someone has to help me with this~
class Solution:
def findWords(self, words: list[str]) -> list[str]:
set1, set2, set3 = set("qwertyuiop"), set("asdfghjkl"), set("zxcvbnm")
#input every row's words
ans = []
for i in words:
t = set(i.lower())
if t <= set1 or t <= set2 or t <= set3:
ans.append(i)
return ans
a=list(input())
b=Solution()
c=b.findWords(a)
print(c)
Traceback (most recent call last):
File "E:/Python文件/Python/Leetcode/leetcode.py", line 9, in <module>
class Solution:
File "E:/Python文件/Python/Leetcode/leetcode.py", line 10, in Solution
def findWords(self, words: list[str]) -> list[str]:
TypeError: 'type' object is not subscriptable##
i have seen many answers about typeeError, i have tried the initialize the definition,but it won't work,actually i don't know what to do