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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:19:40+00:00 2026-05-27T02:19:40+00:00

ive been attempting this problem for a while and I cant seem to get

  • 0

ive been attempting this problem for a while and I cant seem to get the issue out.

listy2=['fun','super','Stop']
listy=['great','life','Stop','toys','nothing','Stop']
listpool=[listy,listy2]
current=[]
total=[]
nested=True
for i in listpool:
    for line in enumerate(i):
        if (line[0]==0):
            current.append(line[1])
            #skipping first line
            continue
        if (line[1].strip()!="") and (nested==True):
            current.append(line[1])
            nested=False
            continue
        if (line[1].strip()=="Stop"):
            nested=True
            continue
    total.append(current)
    #current[:] = []
print total

The program should output a list of lists.
[[first element of list, nested things],[first element of list, nested things]]

Nested things are like:

hello
blah blah
Stop

the nested thing in this case would be hello
The lists can have multiple nested things.

cool
blah blah
Stop
good
blah blah
Stop

the nested thing in this example would be cool and good, (as you can tell, the things in the middle do no matter)

In my code it SHOULD output

[['fun','super'],['great','life','toys']]

however it does not.

Sorry if I cannot explain this question well, as English is not my first language but I am getting used to it. If you have any questions or comments please comment here. Sorry if I have done something stupid. It would also be nice if you could explain my error, but that would not be necessary.
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-05-27T02:19:40+00:00Added an answer on May 27, 2026 at 2:19 am

    I don’t quite understand everything you’re trying to do here, but the simplest answer is that you’re not clearing the ‘current’ list in between outer loop iterations.

    Try it like this:

    listy2=['fun','super','Stop']
    listy=['great','life','Stop','toys','nothing','Stop']
    listpool=[listy,listy2]
    total=[]
    nested=True
    for i in listpool:
        current=[]
        for line in enumerate(i):
            if (line[0]==0):
                current.append(line[1])
                #skipping first line
                continue
            if (line[1].strip()!="") and (nested==True):
                current.append(line[1])
                nested=False
                continue
            if (line[1].strip()=="Stop"):
                nested=True
                continue
        total.append(current)
    print total
    

    This is (slightly) more idiomatic python:

    listy=['great','life','Stop','toys','nothing','Stop']
    listy2=['fun','super','Stop']
    listpool=[listy,listy2]
    
    total=[]
    for i in listpool:
        nested=True
        current=[]
        for (n, line) in enumerate(i):
            if (n==0):
                current.append(line) #skipping first line
            elif nested and line.strip():
                current.append(line)
                nested=False
            elif line.strip()=="Stop":
                nested=True
        total.append(current)
    print total
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been attempting to figure this out for a little while now, and it's
Ive been smashing my head with this for a while. I have 2 completely
I've been laboring over this problem for the past two days. I am attempting
Ive been tryin to solve this for a long time and now know why
There is probably a simple solution to this problem I've been having all night.
I thought this would be a common problem, but I haven't been able to
I'm hoping that someone can help me with this issue. I've been racking my
I've been stuck with this problem for over a week now. Hopefully some one
I have been tasked with attempting to fix a problem with session management in
So this Python problem has been giving me problems since I've tried refactoring 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.