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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:28:24+00:00 2026-06-14T22:28:24+00:00

I catch myself doing this a lot. The example is simple, but, in practice,

  • 0

I catch myself doing this a lot. The example is simple, but, in practice, there are a lot of complex assignments to update data structures and conditions under which the second recursion is not called.

I’m working with mesh data. Points, Edges, and Faces are stored in separate dictionaries and “pointers” (dict keys) are heavily used.

import itertools

class Demo(object):
    def __init__(self):
        self.a = {}
        self.b = {}
        self.keygen = itertools.count()

    def add_to_b(self, val):
        new_key = next(self.keygen)
        self.b[new_key] = val
        return new_key

    def recur_method(self, arg, argisval=True):
        a_key = next(self.keygen)
        if argisval is True:
            # arg is a value
            b_key = self.add_to_b(arg)
            self.a[a_key] = b_key
            self.recur_method(b_key, argisval=False)
        else:
            # arg is a key
            self.a[a_key] = arg

demo = Demo()
demo.recur_method(2.2)

Is there a better way? short of cutting up all of my assignment code into seven different methods? Should I be worried about this anyway?

  • 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-14T22:28:25+00:00Added an answer on June 14, 2026 at 10:28 pm

    Try

    def recur_method(self, key=None, val=None):
        if key is None and val is None:
           raise exception("You fail it")
    

    If None is a valid input, then use a guard value:

    sentinel = object()
    def recur_method(self, key=sentinel, val=sentinel):
        if key is sentinel and val is sentinel:
           raise exception("You fail it")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find myself having a lot of this in different methods in my code:
Hopefully this is a quickie: I've been doing a lot of Java/Google Web Toolkit
I often catch myself doing the following (in non-critical components): some_small_struct *ptr=(some_small_struct *) malloc(sizeof(some_small_struct));
I've found myself doing too much error handling with try\catch statements and getting my
Usually I handle my bugs by myself but this time I need help of
I want to track users who have read my mails.I am doing this but
I have gotten myself into a catch 22 and cannot seem to find my
I need to catch or filter a number from string example: var Mystring =
i want to catch the data from server as an answer and alert it.
I find myself breaking this pattern all the time. YAGNI - You Ain't Gonna

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.