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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:09:37+00:00 2026-06-14T14:09:37+00:00

I was looking for a way to create multiple ad-hoc copies of a dictionary

  • 0

I was looking for a way to create multiple ad-hoc copies of a dictionary to hold some “evolutionary states”, with just slight generational deviations and found this little prototype-dict:

class ptdict(dict):
    def asprototype(self, arg=None, **kwargs):
        clone = self.__class__(self.copy())
        if isinstance(arg, (dict, ptdict)):
            clone.update(arg)
        clone.update(self.__class__(kwargs))        
        return clone

Basically i want smth. like:

generation0 = dict(propertyA="X", propertyB="Y")
generations = [generation0]

while not endofevolution():
    # prev. generation = template for next generation:
    nextgen = generations[-1].mutate(propertyB="Z", propertyC="NEW")  
    generations.append(nextgen)

and so on.

I was wondering, if the author of this class and me were missing something, because i just can’t imagine, that there’s no standard-library approach for this. But neither the collections nor the itertools seemed to provide a similar simple approach.

Can something like this be accomplished with itertools.tee?

Update:
It’s not a question of copy & update, because, that’s exactly what this ptdict is doing. But using update doesn’t return a dict, which ptdict does, so i can for example chain results or do in-place tests, which would enhance readability quite a bit. (My provided example is maybe a bit to trivial, but i didn’t want to confuse with big matrices.)

I apologise for not having been precise enough. Maybe the following example clarifies why i’m interested in getting a dictionary with a single copy/update-step:

nextgen = nextgen.mutate(inject_mutagen("A")) if nextgen.mutate(inject_mutagen("A")).get("alive") else nextgen.mutate(inject_mutagen("C"))
  • 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-14T14:09:38+00:00Added an answer on June 14, 2026 at 2:09 pm

    I guess you’re looking for something like this:

    first = {'x':1, 'y':100, 'foo':'bar'}
    second = dict(first, x=2, y=200) # {'y': 200, 'x': 2, 'foo': 'bar'}
    

    See dict

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

Sidebar

Related Questions

I'm looking for a way to run some TestNG tests against multiple DataSource s.
I am looking for some way to create a queue of sorts for a
I'm looking for way to create list view as like in IOS with pinned
I looking for a way to create Delta Diff Patches of Large Binary Files
I'm looking for a way to create a function that can be used in
I'm looking for a way to create an automatic forwarder (web-browser userscript) if a
I'm looking for a way to create a QR Code and a shortened link
I am looking for a way to create figure that contains several subplots which
I am looking for a way to create a program in unmanaged c++ that
I'm looking at a way to create a summary of transactions within a certain

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.