0

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

1
  • I am working on a Leetcode test about keyboard rows,and i dont know the exactly meaning of that(actually i cant 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~ Commented May 8, 2019 at 5:43

1 Answer 1

2

The problem is the function type signature. You need to import typing

from typing import List

class Solution:
    def findWords(self, words: List[str]) -> List[str]:
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.