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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:05+00:00 2026-06-17T12:33:05+00:00

If I make a list in one function, and edit it, then I want

  • 0

If I make a list in one function, and edit it, then I want to be able to pass the finished list off to another function where it will be used to do more things.

def func1():
    numbers = [1, 2, 3, 4]
    if numbers.count(1) > 0:
        numbers.remove(1)
        func2()

def func2():
    two = numbers[0]

func1()

How could I get it so that it doesn’t pull the error numbers not defined globally. I know why it is pulling the error, but after researching, I still can’t find a good way to fix this problem.

  • 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-17T12:33:06+00:00Added an answer on June 17, 2026 at 12:33 pm

    Based on your mileage and requirement, choose one

    1. Pass the list as a parameter to the called function

      def func2(numbers):
          two = numbers[0]
      
      
      def func1():
          numbers = [1, 2, 3, 4]
          if numbers.count(1) > 0:
              numbers.remove(1)
              func2(numbers)
      
    2. Make both the functions part of a single Class and make the list an instance attribute

      class Foo(object):
          def __init__(self, numbers):
              self.numbers = numbers
              pass
          def func1(self):
              if self.numbers.count(1) > 0:
                  self.numbers.remove(1)
                  self.func2()
          def func2(self):
              two = self.numbers[0]
      
      
      Foo([1, 2, 3, 4]).func1()
      
    3. Redesign so that the called function is decorated with the caller

      def func1(func):
          def wraps(*argv):
              numbers = argv[0]
              if numbers.count(1) > 0:
              numbers.remove(1)
              func(*argv)
          return wraps
      
      @func1
      def func2(numbers):
          two = numbers[0]
      
      
      func2([1,2,3,4])
      
    4. Closure with nested function

      def func1():
          def func2():
              two = numbers[0]
          numbers = [1, 2, 3, 4]
          if numbers.count(1) > 0:
              numbers.remove(1)
              func2()
      
      
      func1()
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a Horizontal List View with two arrows, one to move
I want to make a list of toolbuttons in QT. The toolbuttons should appear
So I am trying to make a Function which returns a list of data,
How I make multiline list comprehension in Python? Something like: [ x for x
I need to make a list with the company that scans the most things...
How can I make a list with pictures and summary (the text under the
I am trying to make a list of links, 6 links in a row.
I am trying to make a list box where I have complete control over
I'm trying to make a list containing different objects. List<Object> list = new ArrayList<Object>();
I'm trying to make unordered list of variables in var1 occurs twice and var2

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.