Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumPythonshallow vs deep copySingle-choice MCQ

A structure contains the same sub-list twice. How do shallow copy and deep copy each treat that shared reference?

import copy shared = [0] data = [shared, shared] sc = copy.copy(data) dc = copy.deepcopy(data) print(sc[0] is sc[1], sc[0] is shared) print(dc[0] is dc[1], dc[0] is shared)