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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:34:24+00:00 2026-06-04T05:34:24+00:00

I am trying to write a wrapper object around the dictionary object in python

  • 0

I am trying to write a wrapper object around the dictionary object in python like so

class ScoredList():
    def __init__(self,dct={}):
        self.dct = dct

list = ScoredList()
list.dct.update({1,2})

list2 = ScoredList()
list.dct.update({"hello","world"})

print list1.dct, list2.dct # they are the same but should not be!

It seems like I am unable to create a new ScoredList object, or rather, every scored list object shares the same underlying dictionary. Why is this?

class ScoredList2():
    def __init__(self):
        self.dct = {}

The above code for ScoredList2 works fine. But I want know how to overload the constructor properly in python.

  • 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-04T05:34:25+00:00Added an answer on June 4, 2026 at 5:34 am

    A dictionary is a mutable object. In Python, default values are parsed when the function is created, meaning the same empty dictionary is assigned to every new object.

    To solve this, simply do something like:

    class ScoredList():
        def __init__(self, dct=None):
            self.dct = dct if dct is not None else {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a COM++ object wrapper around a Qt widget (control) I
I'm trying to write a simple database wrapper class. I've written a method like
I am trying to write a wrapper around a legacy COM object and install
I'm trying to write a wrapper around Image_Graph bar charts. I actually wrote the
I am trying to write a simple wrapper around a connection pointer that will
I am trying to write a simple wrapper around log4net for my team, but
When writing a class to act as a wrapper around a heap-allocated object, I
I have an OLE COM object that trying to write a wrapper for, I
I'm trying to build an object that looks something like this: public class MyObject
I'm trying to write some wrapper class or function that allows me to execute

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.