Question: python language, learning if-statements, loops and lists Write a function brackets (expr) that takes a string consisting only of the symbols (, ). 1 and]

python language, learning if-statements, loops and lists

 python language, learning if-statements, loops and lists Write a function brackets(expr) that takes a string consisting only of the symbols (, ).

Write a function brackets (expr) that takes a string consisting only of the symbols (, ). 1 and] and analyzes the string to make sure that the brackets are all "balanced" (matched) properly. For example the strings O1' and COI))]) contain balanced brackets, whereas 'OO OP LO)' and' (LO]l' are unbalanced. We refer to (.( and I as "left brackets", and), and ] as "right brackets". The basic algorithm to implement works like this: input: a string S output: a list L for each character in S if the character is a left bracket else if the character is a right bracket, but L is empty else if the character is a right bracket and append the character to L return the string 'error the rightmost element of L is a matching left bracket

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!