Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:40:02+00:00 2026-06-07T19:40:02+00:00

So i need a way for python to basically detect the difference between a

  • 0

So i need a way for python to basically detect the difference between a string that looks like this:

W:1.0,X:1.1(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8)Y:0.9

and this:

A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8

Is there any function that can be used to detect that in the first string, there are 2 inner parenthesis following each other, whereas in the second string, the first inner parenthesis is eventually followed by a closed parenthesis?
It would be best if it is not a .re regular expression.
Thanks!

Edit:
I am dealing with ANY case of parenthesis, anything from:

A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8,(T:0.6,V:0.7)S:0.8,(D:0.6,Y:0.7)P:0.8,(X:0.6,L:0.7)M:0.8

ANY infinite amount on inner 2 child strings…
To:

W:1.0,X:1.1(U:5.0(I:9.0)N:8.0,(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8)R:3.4(O:5.5)P:3.0)Y:0.9

A highly complicated multiple child-fielded string, that can contain any infinite amount of children with their own children

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:40:05+00:00Added an answer on June 7, 2026 at 7:40 pm
    s = 'W:1.0,X:1.1(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5,(F:0.6,G:0.7)H:0.8)Y:0.9'
    
    def max_depth(s, start_ch='(', end_ch=')'):
        depth = 0
        best = 0
        for ch in s:
            if ch == start_ch:
                depth += 1
                best = max(depth, best)
            elif ch == end_ch:
                depth -= 1
                if depth < 0:
                    raise ValueError('illegal string - unmatched close-paren')
        if depth:
            raise ValueError('illegal string - unmatched open-paren')
        return best
    
    print max_depth(s)    # => 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unicode string in Python and basically need to go through, character
Is there a nice linqy way of splitting a FormCollection into a Dictionary<string,string> that
I need fastest way to convert files from latin1 to utf-8 in python. The
I need to download several files via http in Python. The most obvious way
I need a way to wait until a (Swing) JComponent is fully painted. This
I am writing some code in Python something like this: import sys try: for
I have a Python function registered as a View in Plone. I need to
The documentation basically says that range must behave exactly as this implementation (for positive
When using the python struct module on can specify a format string that declares
Is there a way to get the Unicode Block of a character in python?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.