EP06 - Python Stack - Balanced Parentheses Checker

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2021
  • #Python #DataStructures #Stacks
    Welcome to the Python Stacks tutorial.
    Following is the repository of the code used in this episode
    github.com/ashwin-pajankar/Py...
  • НаукаНаука

Комментарии • 13

  • @venkatkrishnan9777
    @venkatkrishnan9777 Год назад +1

    Super amazing explanation

  • @shankarkarunakaran5819
    @shankarkarunakaran5819 Год назад +2

    stack is not defined error

  • @yuvrajdarekar3494
    @yuvrajdarekar3494 Год назад

    It will not work for nested parenthesis

  • @PedroCarneiroJr1971
    @PedroCarneiroJr1971 11 месяцев назад +1

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

    • @swethag040
      @swethag040 8 месяцев назад +1

      Pls share the code

    • @PedroCarneiroJr1971
      @PedroCarneiroJr1971 8 месяцев назад

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

    • @PedroCarneiroJr1971
      @PedroCarneiroJr1971 5 месяцев назад

      Hey brother @@swethag040 , I am preparing a video to show my solution. I am newbie to this RUclips 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.

  • @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 Год назад +2

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

  • @DATA_MACHINE22
    @DATA_MACHINE22 Год назад

    wow

  • @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))