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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:54:44+00:00 2026-05-31T23:54:44+00:00

Lets say I have a recursive function that creates lists within lists. It return

  • 0

Lets say I have a recursive function that creates lists within lists. It return something along the lines of:

['a', ['b', ['c', ['d', []]]], 'z', []]

Lets call this list LIST1

Then I have a function that takes that list, and cleans it up for me, essentially removing the z.Lets call this list LIST2

[a,b,c,d]

What I can do, is call my first function and receive my list, and then(while in the python shell) call my cleanup function on LIST1 to convert it to LIST2. What I’d like to do is have cleanup operate as soon as LIST1 is returned, essentially having cleanup operate within my list generator function.

I’m puzzled on how I’m supposed to call a function that changes the result of a recursive function without screwing up the recursive function.

I don’t want to go into specifics of my code, since it’s fairly complicated and heavily nested, but ask questions if you’d like me to clarify.

If it helps to visualize a problem, imagine it in simpler terms. I have a function that returns a value, I want another function to operate on that value, but within the first function.

Cheers,

  • 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-31T23:54:45+00:00Added an answer on May 31, 2026 at 11:54 pm

    Is this what you were trying to do ?

    import collections
    
    result = ['a', ['b', ['c', ['d', []]]], 'z', []]
    
    def get_result() :
        for r in result :
            yield r
    
    
    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
    
    
    def remove_z(l) :
        for i in l :
            if i != 'z' :
                yield i
    
    print [ l for l in remove_z(flatten(get_result()))]
    

    And the result is

    ['a', 'b', 'c', 'd']
    

    The ‘flatten’ function comes from here : https://stackoverflow.com/a/2158532/16718

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have one table called REVIEWS This table has Reviews that customers
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say I have a loop in Bash: for foo in `some-command` do do-something
Lets say I have hierarchy like this (This is just a test program. Please
Lets say I have this class (simplified): class Tag (...): children = models.ManyToManyField(null=True, symmetrical=False)
I have a problem with recursive CTE query Let's say that I have that
Let's say I have a table called my_table that looks like this: id |
Let's say I have a basic recursive function: function recur(data) { data = data+1;
Lets say I have multiple DataGrids throughout my winform app and I want to

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.