Avatar ·

Correct bracket sequence stack python [duplicate]

📁 Conditions, Advanced Python Topics, question

(6 answers)
Closed 8 years ago.

Hello everyone, who can help with implementing a check for correct bracket sequence using a stack in Python. I know the essence of the check and implemented it simply with conditions, but I can't figure it out with a stack, please help.

def brackets_check(s):meetings = 0for c in s:    if c == '(':        meetings += 1    elif c == ')':        meetings -= 
                        
                    
Avatar ·

There are several options:

f.write("""".join(list).join(""""));

for item in list:    f.write(""%s"" % item)

import pickle# Good option for non-string lists, because we use serialization# with pickle. Can serialize to json or, for example, xml.pickle.dump(list, f)

P.S The first option is good because all actions are done

Log in to leave an answer

Blogs