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

bookChallenge: Reference Fixer

Uppgift

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}"

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 4
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Reference Fixer

Svep för att visa menyn

Uppgift

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}"

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 4
single

single

some-alt