EP06 - Python Stack - Balanced Parentheses Checker

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • #Python #DataStructures #Stacks
    Welcome to the Python Stacks tutorial.
    Following is the repository of the code used in this episode
    github.com/ash...

ความคิดเห็น • 13

  • @PedroCarneiroJr1971
    @PedroCarneiroJr1971 ปีที่แล้ว +1

    Guys, I use the python strings approach. Very simple and effective.

    • @swethag040
      @swethag040 9 หลายเดือนก่อน +1

      Pls share the code

    • @PedroCarneiroJr1971
      @PedroCarneiroJr1971 9 หลายเดือนก่อน

      Hi @@swethag040 I'll try to find it at my computer at home and share it here.

    • @PedroCarneiroJr1971
      @PedroCarneiroJr1971 6 หลายเดือนก่อน

      Hey brother @@swethag040 , I am preparing a video to show my solution. I am newbie to this TH-cam production thing so that is taking time to have the nerves to do it, but I promisse the solution is interestingly simpler. As soon as it is ready I'll let you know it here under this comment.

  • @venkatkrishnan9777
    @venkatkrishnan9777 2 ปีที่แล้ว +1

    Super amazing explanation

  • @shankarkarunakaran5819
    @shankarkarunakaran5819 ปีที่แล้ว +2

    stack is not defined error

  • @YouWillSUffer____
    @YouWillSUffer____ ปีที่แล้ว +2

    Sir but if won't work let's say ({) } it is actually balanced still it shows False
    it's because we are popping { but char will )

    • @rahulmittal116
      @rahulmittal116 ปีที่แล้ว +3

      Above expression is not balanced..
      Type of bracket opened at last should be closed first

  • @yuvrajdarekar3494
    @yuvrajdarekar3494 ปีที่แล้ว

    It will not work for nested parenthesis

  • @machinelearningtensorflow8382
    @machinelearningtensorflow8382 2 ปีที่แล้ว +2

    Can I do it using dict??

    • @aryanraje2770
      @aryanraje2770 2 ปีที่แล้ว

      Yes you can.
      openingparenthesis = '[{('
      closingparenthesis = ')}]'
      openingList = []
      exp = '(){'
      pairs = {')':'(', '}':'{',']':'['}
      def checkParenthesis(exp):
      for i in exp:
      if i in openingparenthesis:
      openingList.append(i)
      elif i in closingparenthesis:
      if openingList==[]:
      return False
      top_char = openingList.pop()
      if pairs[i] != top_char:
      return False
      if openingList== []:
      return True
      else:
      return False
      print(checkParenthesis(exp))

  • @DATA_MACHINE22
    @DATA_MACHINE22 ปีที่แล้ว

    wow