79381747

Date: 2025-01-23 16:00:27
Score: 0.5
Natty:
Report link

You could try a linked list for this task.

Lets say you have elements A B C F G to be added your class. Your clas should remember first and most recent element. You can add A in a format it pounts to a and next element. Lets call it node

When you add B you update A node and your main object. Then when you add C you only update B node and main object. Then when you add D you only update C node and main object.

So each time you only update last Last node and your object to remember your last node.

Although it still updates your object your object consists of data for only name of 2 objects and you only update the last node so big amonut of data that is stored inside all of your other nodes (other then first and last) are not even reached in this process let alone being deleted and re-writed. So if you have 1 million elements iside your list you only update node for last element to point your freshly added element.

Then you can pickle all the nodes between keeping them same structure.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Onuralp Arslan