Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Modify the **bracketsBalance** function so that the caller can supply the brackets to match as arguments to this function. The second argument should be a

Modify the **bracketsBalance** function so that the caller can supply the brackets to match as arguments to this function. The second argument should be a list of beginning brackets, and the third argument should be a list of ending brackets. The pairs of brackets at each position in the two lists should match; that is, position 0 in the two lists might have [ and ], respectively. You should be able to modify the code for the function so that it does not reference literal bracket symbols, but just uses the list arguments. (Hint: The method index returns the position of an item in a list.)

Please use the template given.

class Stack: ''' TODO: Remove the "pass" statements and implement each method Add any methods if necesssary DON'T use any builtin stack class to store your items ''' def __init__(self): # Constructor function pass def isEmpty(self): # Returns True if the stack is empty or False otherwise pass def len(self): # Returns the number of items in the stack pass def peek(self): # Returns the item at the top of the stack pass def push(self, item): # Adds item to the top of the stack pass def pop(self): # Removes and returns the item at the top of the stack pass def bracketsBalance(input_str,opening_list,closing_list): isBalanced = True stk=Stack() #TODO: Your work here

# Return if input_str is balanced or not return isBalanced if __name__ == "__main__": my_str = "([{))}" opening_list=['(', '[', '{'] closing_list=[')', ')', '}'] print(bracketsBalance(my_str,opening_list,closing_list)) # Correct Output: False #TODO (optional): Your testing code here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions