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

  • Home
  • SEARCH
  • 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 7940707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:27:36+00:00 2026-06-03T23:27:36+00:00

I asked a while ago about how to make a list of sublists (and

  • 0

I asked a while ago about how to make a list of sublists (and of even more sublists) from a string given delimiters here.
How to process a string into layer of sublists

Now, I need to join them back together and I’m not sure how. I have tried to look here
Python : Recursively flatten a list
and
Flatten a list in python

However, neither of these answers work in my case because chain splits my string (single item “lists”) into characters, and then therefore cannot join with “\n”, and reduce does not concatenate str and list objects.

I will probably need to walk through the sublists (and their sublists) at some point. Is there a way to iterate through each level of sublist? (I can leave this as a separate question, one step at a time.. but just wondering whether this process is making sense or should I try an entire new method. I do think logically this makes the most sense, I’m just having trouble navigating it.)

Thanks.

  • 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-03T23:27:37+00:00Added an answer on June 3, 2026 at 11:27 pm

    I’m going to assume what I said in the comment is correct unless you say otherwise.

    From the posts you linked, you have:

    import collections
    
    def flatten(l):
        for el in l:
            if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
                for sub in flatten(el):
                    yield sub
            else:
                yield el
    

    to recursively flatten an irregular list of lists, and

    def go(it):
        for x in it:
            if x == 'b':
                yield [x] + list(go(it))
            else:
                yield x
                if x == 'c':
                    break
    

    to create that irregular list of lists from an iterator.

    The inverse of go is just flatten(output_of_go) so the inverse of go(iter(string)) is ''.join(flatten(output_of_go)). You can see that with this test code:

    lst = "aaabaabacabaacaca"
    assert ''.join(flatten(go(iter(lst)))) == lst
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked here a while ago about matching text inside of two wrapped <code>..</code>
A while ago I asked about std::string constants correct idiom for std::string constants? .
I've asked here a ton of questions about WSAAsyncSelect and NET.Few months ago I
I asked a question while ago about accessing the underlying container of STL adapters
A while ago I asked this question about how to defer updates to an
Quite a while ago, someone asked how you can make Visual Studio's debugger play
A while ago I had asked how to make a collapsible comment box like
I asked a question a while ago about which local DB was right for
A while ago I asked a question about square detection and karlphillip came up
a while ago, i asked about how to implement a REST api. i have

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.