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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:29:00+00:00 2026-06-03T11:29:00+00:00

This is the example form, I’ll try to explain it in words later. I

  • 0

This is the example form, I’ll try to explain it in words later.
I have a list from breaking up a string…

say

[a, a, a, b, a, a, b, a, c, a, b, a, a, c, a, c, a]

where b is criteria 1 and c is criteria 2

I want to break it into a list like this:

[a, a, a, [b, a, a, [b, a, c], a, [b, a, a, c], a, c], a]

So I want to process the string such that when I go through it, if the item matches criteria 1, open a new list, if item matches criteria 2, close the list and return one level above.

I’ve tried to do something like this, but it’s not working very well.

def sublist(self, l):
  for line in list:
    if not b:
    self.data.append(line)
  else:
    sublist(l[line:])       #<-----  not sure how to recurse it.

I’ve seen breaking list into equal sized list before on stackoverflow, but not one breaking into sublist using a set of criteria.

  • 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-03T11:29:02+00:00Added an answer on June 3, 2026 at 11:29 am

    here you go:

    lst = "aaabaabacabaacaca"
    
    def go(it):
        for x in it:
            if x == 'b':
                yield [x] + list(go(it))
            else:
                yield x
                if x == 'c':
                    break 
    
    
    print list(go(iter(lst)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a url in this form http://www.example.com/data/45 . How do I get the
I have this struct: Example.Form = Ext.extend(Ext.form.FormPanel, { // other element , onSuccess:function(form, action)
I have this example simple code to enable and disable a form according to
I have this example : <form action=form_action.asp> <select multiple=multiple name=example size=10> <option value=foo>Foo</option> <option
Based on this example I have imported the VLC ActiveX. When I try to
For example if i have form like this: <form > <input type=text name=name id=my_input>
Hello i am using Zend Framework Form and have tried to get this example
Below example is taken from this documentation page: https://github.com/activescaffold/active_scaffold/wiki/Chaining-Form-Fields [Example start] You can set
In this example , employee structs are parsed in the form employee{int, string, string,
Example form, https://stackoverflow.com/questions/ask and I save this page to desktop. Then I edit the

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.