Data formats: XML, INI, TOML and pickle · 14 / 15 Exercise Hard

Copy data with pickle

Objective

pickle serializes almost any Python object to bytes and rebuilds it later. It is handy between your own programs, but you must never load a pickle that comes from an untrusted source: loading it can run code.

Instructions

  • The first line has the number n of people; each one is a line name age.
  • Store in a dictionary the list people of tuples and the dictionary ages. Serialize it with pickle.dumps and recover it with pickle.loads.
  • Show Equal copy: True, Different object: True (the copy is not the same object) and the people of the copy sorted by age and then by name.
Input
3
ana 30
luis 25
eva 30
Output
Equal copy: True
Different object: True
luis 25
ana 30
eva 30

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise