Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Pickling in Python

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Pickling in Python. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

What is pickling and unpickling?

Asked in the 1st Round Technical Interview stage. Implement a function that pickles a JSON-compatible Python object into bytes and then unpickles those bytes to reconstruct the object.

Function

def pickle_round_trip(obj):

The function accepts one JSON-compatible value, including None, booleans, numbers, strings, lists, and dictionaries, and returns the reconstructed value. The returned value must compare equal to the original input.

Constraints

  • The input is one JSON-compatible Python value.
  • Supported values include null, booleans, numbers, strings, lists, and dictionaries.
  • The input contains at most 1,000 nested elements.
  • The serialized data is produced and consumed within the function.

Function Signature

def pickle_round_trip(obj):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output