Python Mutable Default Parameters in 5 minutes: A common misunderstanding (and memoization)

preview_player
Показать описание
Over the next 5 minutes we'll cover what is an all too common misunderstanding in novice (and intermediate) python learners. We'll also look at how we can use this to our advantage to create memoization functions.
Рекомендации по теме
Комментарии
Автор

You sir have officially blown my mind to bits.... I had no idea about this. Can't wait for more videos from you.

Sra
Автор

Great explanation! I wish you had mentioned functools.lru_cache from the standard library as a better way to accomplish memoization, but otherwise a useful thought experiment for understanding the fundamentals.

traal
Автор

Using default parameter to store memoization is genius!

adsfwef
Автор

need to use memoization technique within the def of fib
not that fib is used in memoization as shown in this video
def fib(n, memo = {}):
if n==0 or n==1 : return n
try:
value = memo[n]
except KeyError :
value = fib(n-1)+fib(n-2)
memo[n] = value
return value
:-)

drsmahesan
join shbcf.ru