Home > Mobile >  I'm having a missing 1 required positional argument issue, but I'm giving it an argument..
I'm having a missing 1 required positional argument issue, but I'm giving it an argument..

Time:12-21

I'm trying to run a leetcode solution through a debugger so I can see how the solution works. Its number 20 on parenthesis. This is what I've plugged into the debugger..am I missing something?

screencapture of what I tried

class Solution:
    def isValid(self, s: str) -> bool:
        parenthesis = {"}":"{", 
        "]":"[", 
        ")":"("
        }
        stack = []
        for i in s:
           if i in parenthesis:
               if not stack or paren[i] != stack[-1]: 
                   return False
        
               else:
                    stack.pop()
           else:
                stack.append(i)
        return stack == []

Solution.isValid("{[]}")

I've tried making an instance of the class but I still get the same issue.

CodePudding user response:

I think you should create the object of a class first.

sol = Solution()
print(sol.isValid("{[]}")

CodePudding user response:

Creating an Object a of a Class Solution

Note you need to use print statment for the output. without print statement your console will show nothing.

class Solution:
    def isValid(self, s: str) -> bool:
        parenthesis = {"}":"{", 
        "]":"[", 
        ")":"("
        }
        stack = []
        for i in s:
           if i in parenthesis:
               if not stack or parenthesis[i] != stack[-1]: 
                   return False
               else:
                    stack.pop()
           else:
                stack.append(i)
        return stack == []

a=Solution()
print(a.isValid("{[]}"))

Output:-

True
  • Related