Removing a temporary changes object sharing

A maintenance team proposes removing a temporary variable from a Python function that creates task queues. Task durations are stored as integer minutes. The proposed change is intended to preserve existing behavior.


Python
# Original version
def make_queues():
    pending = []
    return pending, pending


Python
# Proposed version
def make_queues():
    return [], []


The following client code runs once with each version, starting with fresh queues each time:


Python
morning, backup = make_queues()
morning.extend([12, 18])
backup.append(7)
morning_total = sum(morning)
backup_total = sum(backup)


Calculate morning_total and backup_total for the original version, then calculate both totals for the proposed version. Enter all four results in minutes, to zero decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Refactoring Questions: