Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Reference Fixer | Mutable Objects and Function Arguments
Common Python Mistakes and How to Fix Them

bookChallenge: Reference Fixer

Task

Swipe to start coding

Complete the function so that you add an item only to the target_list without affecting other_list. Sometimes, both lists may refer to the same underlying object, so be careful to avoid unwanted side effects.

  • Check if target_list and other_list refer to the same object.
  • If they do, create a new list for target_list that contains the same elements as before.
  • Add item to target_list.
  • Print both lists using these templates:
    • "Target list: {target_list}"
    • "Other list: {other_list}"

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Reference Fixer

Swipe to show menu

Task

Swipe to start coding

Complete the function so that you add an item only to the target_list without affecting other_list. Sometimes, both lists may refer to the same underlying object, so be careful to avoid unwanted side effects.

  • Check if target_list and other_list refer to the same object.
  • If they do, create a new list for target_list that contains the same elements as before.
  • Add item to target_list.
  • Print both lists using these templates:
    • "Target list: {target_list}"
    • "Other list: {other_list}"

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 4
single

single

some-alt