Quantcast
Channel: parsing nested parentheses in python, grab content by level - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Nitesh Mistry for parsing nested parentheses in python, grab...

Below is my Python solution with a time complexity of O(N)str1 = "(a(b(c)d)(e(f)g)hi)"def content_by_level(str1, l): level_dict = {} level = 0 level_char = '' for s in str1: if s == '(': if level not...

View Article



Answer by Olivier Melançon for parsing nested parentheses in python, grab...

Parentheses matching requires a parser with a push-down automaton. Some libraries exist, but the rules are simple enough that we can write it from scratch:def push(obj, l, depth): while depth: l =...

View Article

Answer by Gareth Rees for parsing nested parentheses in python, grab content...

You don't make it clear exactly what the specification of your function is, but this behaviour seems wrong to me:>>> ParseNestedParen('(a)(b)(c)', 0)['a)(b)(c']>>>...

View Article

Answer by justin cress for parsing nested parentheses in python, grab content...

#!/usr/bin/env pythonimport redef ParseNestedParen(string, level):""" Generate strings contained in nested (), indexing i = level""" if len(re.findall("\(", string)) == len(re.findall("\)", string)):...

View Article

parsing nested parentheses in python, grab content by level

Apparently this problem comes up fairly often, after reading Regular expression to detect semi-colon terminated C++ for & while loopsand thinking about the problem for a while, i wrote a function...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images