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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:56:09+00:00 2026-05-15T20:56:09+00:00

In a function, I need to perform some logic that requires me to call

  • 0

In a function, I need to perform some logic that requires me to call a function inside a function. What I did with this, like:

def dfs(problem):
   stack.push(bache)
   search(root)              
   while stack.isEmpty() != 0:


  def search(vertex):
     closed.add(vertex)
     for index in sars:
        stack.push(index)
        return stack

In the function, dfs, I am using search(root), is this is the correct way to do it?

I am getting an error: local variable ‘search’ referenced before assignment

  • 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-15T20:56:10+00:00Added an answer on May 15, 2026 at 8:56 pm

    There are many mysterious bug-looking aspects in your code. The wrong order of definition (assuming you do need the search function to be a nested one) and the syntax error from the empty while loop have already been observed, but there are more…:

    def dfs(problem):
       stack.push(bache)
       search(root)              
    

    what’s bache, what’s stack, what’s root? If they’re all global variables, then you’re overusing globals — and apparently nowhere ever using the argument problem (?!).

       while stack.isEmpty() != 0:
    

    what’s this weird-looking method isEmpty? IOW, what type is stack (clearly not a Python list, and that’s weird enough, since they do make excellent LIFO stacks;-)…? And what’s ever going to make it empty…?

      def search(vertex):
         closed.add(vertex)
    

    …don’t tell me: closed is yet another global? Presumably a set? (I remember from a few of your Qs back that you absolutely wanted to have a closed dict, not set, even though I suggested that as a possibility…

         for index in sars:
    

    …and what’s sars?!

            stack.push(index)
            return stack
    

    what a weird “loop” — one that executes exactly once, altering a global variable, and then immediately returns that global variable (?) without doing any of the other steps through the loop. Even if this is exactly what you mean (push the first item of sars, period) I don’t recommend hiding it in a pseudo-loop — it seriously looks like a mystery bug just waiting to happen;-).

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

Sidebar

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.