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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:16:11+00:00 2026-05-25T19:16:11+00:00

I can’t figure out what I’m doing wrong. I have to create a nested

  • 0

I can’t figure out what I’m doing wrong. I have to create a nested list(of possible solutions to a problem), so I created a class that appends a solution to a list of existing solutions(since each solution is being calculated one at a time)

This function works fine:

def appendList(list):
    #print list
    list2.append(list)

x =0
while x < 10:
    x = x+1
    one = "one"
    two = "two"
    appendList([(one), (two)])

print list2

with a result of:

[['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two'], ['one', 'two']]

but when I take this exact same function and put it in a class, I get an error saying:

TypeError: appendList() takes exactly 1 argument (2 given)

Here’s the class and how I call it:

class SolutionsAppendList:
    list2 = []
    def appendList(list):
    #print list
        list2.append(list)
appendList.appendList([('one'), ('two')])

I’m sure I’m making a very basic error but I can’t seem to figure out why, since I’m using the same function in the class.

Any suggestions/advice would be great.
Thanks

  • 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-25T19:16:11+00:00Added an answer on May 25, 2026 at 7:16 pm

    Since you’re dealing with classes here, it’s important to use instance variables. These can be accessed by using the self keyword. And if you’re dealing with class methods, be sure to make their first argument self. So, modified…

    class SolutionsAppendList:
        def __init__(self):
            self.list = []
    
        def appendList(self, list):
        #print list
            self.list.append(list)
    

    What’s cool about this is that you no longer need list2. Instance variables (self.list). Are different than local variables (the list you pass to the appendList() method). EDIT: I”ve also added an __init__ method, which is called once an instance of the SolutionsAppendList object is created. In my first reply, I overlooked the fact that self.* is not available outside of a method. This is the edited code (Thanks David).

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

Sidebar

Related Questions

Can you cast a List<int> to List<string> somehow? I know I could loop through
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
Can I call a java class method from inside a flash movie?
Can we have two main() functions in a C++ program?
Can anyone help me as what is going wrong here? Am not able to
Can anyone provide the XAML for creating customized check boxes. I have attached the
Can somebody give me advice on how to create a recursive version of GetEnumerator()?
can anyone tell me if it is possible to convert a dojo charting object
Can't work out a way to make an array of buttons in android. This

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.