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 9232071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:13:34+00:00 2026-06-18T06:13:34+00:00

What I have is a string that looks for example like this {[]}{([])}() and

  • 0

What I have is a string that looks for example like this {[]}{([])}()and I loop it through to find if it is an open or a close bracket and append it to the list.
What I wanna do now is to find which is the deepest nasting and print it out. So in this example i would print the middle {([ but I am confused how to do it. I can append the beginning of the open brackets and then reset it but how to compare couple of them though, and printing the biggest one

my code:

def is_nested(str):
    stack = []
    deepest =[]
    index=1
    open=0
    for c in str:
        if c == "{" or c == "(" or c == "[" or c =="<":
            stack.append(c) # this is push
            deepest.append(c)
            open +=1
            index +=1
        elif c == "}":
            x = stack.pop()
            index +=1
            if x != "{":
                index -=1
                x2=parens(x)
                return "False: expected %s at character index %d, but received } instead." %(x2,index)
        elif c == "]":
            x = stack.pop()
            index +=1
            if x != "[":
                index -=1
                x2=parens(x)
                return "False: expected %s at character index %d, but received ] instead." %(x2,index)
        elif c == ">":
            x = stack.pop()
            index +=1
            if x != "<":
                index -=1
                x2=parens(x)
                return "False: expected %s at character index %d, but received > instead." %(x2,index)
        elif c == ")":
            x = stack.pop()
            index +=1
            if x != "(":
                index -=1
                x2=parens(x)
                return "False: expected %s at character index %d, but received ) instead." %(x2,index)

    check(str)
    return True
def check(str):
    deepest =[]
    for c in str:
        if c == "{" or c == "(" or c == "[" or c =="<":
            deepest.append(c)
    print deepest


def parens(x):
    if x == "<":
        return ">"
    elif x =="(":
        return ")"
    elif x == "{":
        return "}"
    elif x == "[":
        return "]"


print is_nested("{[()}")
print is_nested("([)")
print is_nested("{[]({})}")
print is_nested("<()>")
print is_nested("{(<)}")
  • 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-18T06:13:35+00:00Added an answer on June 18, 2026 at 6:13 am

    Not sure if I understand your wishes correctly, but this finds the longest sequence of successive opening brackets:

    In [20]: import re
    
    In [21]: s = '{[]}{([])}()'
    
    In [22]: max(re.findall("[\(\[\{]+",s),key=len)
    Out[22]: '{(['
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that looks like string url = "www.example.com/aaa/bbb.jpg"; "www.example.com/" is 18
I have a String that looks like this String = Förpackning Flaska (375 ml)
I have a string that looks like this: <name>-<gender>-<age>.jpg I want to be very
I have a string that looks like this: 9/1/2009. I want to convert it
i have a string that looks like this: sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi
Problem: I have a string that looks like this: [1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18] Question: How can you
I have a huge string that looks like this: Text Text Text Text Text
I have a JSON string that looks like this: { package1: { type: envelope,
I have a string that looks something like: 'a 'b '(d f g (1
If I have a string that looks like either ./A/B/c.d OR .\A\B\c.d How do

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.