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

bookChallenge: Reference Fixer

Tâche

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

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

Glissez pour afficher le menu

Tâche

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 desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 4
single

single

some-alt