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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:35:16+00:00 2026-05-16T14:35:16+00:00

I have a class where each instance is basically of a bunch of nested

  • 0

I have a class where each instance is basically of a bunch of nested lists, each
of which holds a number of integers or another list containing integers, or a
list of lists, etc., like so:

class Foo(list):
    def __init__(self):
        self.extend(
            list(1), list(2), list(3), range(5), [range(3), range(2)]
            )

I want to define a method to walk the nested lists and give me
one integer at a time, not unlike os.walk. I tried this:

def _walk(self):
    def kids(node):
        for x in node:
            try:
                for y in kids(x):
                    yield y
            except TypeError:
                yield x
    return kids(x)

But it immediately raises a stopiteration error. If I add a print statement to print each “node” in the first for loop, the function appears to iterate over the whole container in the way I want, but without yielding each node. It just prints them all the first time I call next on the generator.

I’m stumped. Please help!

  • 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-16T14:35:17+00:00Added an answer on May 16, 2026 at 2:35 pm

    It works if you change return kids(x) to return kids(self)

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

Sidebar

Related Questions

I have a class library containing several structures each consisting of several value and
Basically I have some class objects, each with three properties. Once one class object
I have a class Person which can have several Homes, each one with one
In C++, I have an Object class, from which a number of other classes
I wish to have a map from classes to instances of each class. The
I have a class for each database table object. Each class takes care of
I have class Foo(): function bar(): pass function foobar(): pass Rather than executing each
I have a class with a custom each-method: class CurseArray < Array def each_safe
i have Segment class who contain 2 sections , each section contain 2 point
I have a class that encapsulates tcp socket communications with a server. For each

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.