Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Temporary List Modification | Practice with Context Managers
Python Context Managers

bookChallenge: Temporary List Modification

Tâche

Swipe to start coding

Create a generator-based context manager using contextlib.contextmanager that temporarily appends an item to a given list when entering the context and removes it when exiting the context.

  • The context manager must append item to the end of lst when entering the context.
  • The context manager must remove the last occurrence of item from lst when exiting the context.
  • The context manager must restore the list to its previous state if an exception occurs inside the context.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 3
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

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Temporary List Modification

Glissez pour afficher le menu

Tâche

Swipe to start coding

Create a generator-based context manager using contextlib.contextmanager that temporarily appends an item to a given list when entering the context and removes it when exiting the context.

  • The context manager must append item to the end of lst when entering the context.
  • The context manager must remove the last occurrence of item from lst when exiting the context.
  • The context manager must restore the list to its previous state if an exception occurs inside the context.

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 3. Chapitre 3
single

single

some-alt