Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Memoization Decorator | Decorator Practice Lab
Python Decorators Explained

bookChallenge: Memoization Decorator

Opgave

Swipe to start coding

Write a decorator that caches the results of a function based on its arguments to avoid redundant calculations.

  • The decorator must store the result of a function call using its positional and keyword arguments as the cache key.
  • When the function is called again with the same arguments, the cached result must be returned instead of recomputing it.
  • The decorator must work for functions with any number of positional and keyword arguments.

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 2
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you explain this in simpler terms?

What are the main takeaways from this?

Can you give me an example?

close

bookChallenge: Memoization Decorator

Stryg for at vise menuen

Opgave

Swipe to start coding

Write a decorator that caches the results of a function based on its arguments to avoid redundant calculations.

  • The decorator must store the result of a function call using its positional and keyword arguments as the cache key.
  • When the function is called again with the same arguments, the cached result must be returned instead of recomputing it.
  • The decorator must work for functions with any number of positional and keyword arguments.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 2
single

single

some-alt