My lecturer spent 2 hours trying to explain this to us didn't understand a thing. You done it in 5 and it makes total sense. THANKS!!
@TrumanBurbonk5 жыл бұрын
Could you explain mi this: if ef_cache changes because result changes then how can old num be recognized? Is ef_cache storing those results without overrunning one with the nex one?
@Girish49445 жыл бұрын
@@TrumanBurbonk yes ef_cache is storing those results without overrunning with the next one.
@monk_5 жыл бұрын
Every time I hear "Memoization" I imagine someone saying "Memorization" in a baby voice.
@Goozeeeee3 жыл бұрын
I'm never going to look at this the same way again
@Poser_Metal_Records9 жыл бұрын
Awesome. Short, simple, and straight to the point. Thank you.
@justgivemethetruth7 жыл бұрын
Yeah, Wikipedia is great
@팍준하4 жыл бұрын
Summary: Memoization refers to the mechanism that makes a function not having to compute the output using an input, when the function has been executed using the same input before. This is possible because the computer memorizes the input:output pair. This tool can be demonstrated in python using an if statement and a dictionary outside the function.
@thinhnguyenvan70034 жыл бұрын
Nice
@corbettknoff51234 жыл бұрын
Whenever I don't understand something and I find a Corey Schafer video I'm always relieved. I know I'm finally going to understand it.
@amr31627 жыл бұрын
Dude you're literally god, I just finished your first class functions, closure, and decorators videos and while watching this I realized how useful it would be to implement memoization using a decorator.
@yacinegaci64027 жыл бұрын
nice thought, it would really show how decorators could be robust and useful
@63montywilliams502 жыл бұрын
been rockin with you for a while now, good content mr chaffer!
@ayizeakono84926 жыл бұрын
All your videos are well organized and delivered....thanks so much for sharing!!!!
@anon-sl4vp6 жыл бұрын
another brilliant video :) love learning about programming terms and such... if you could do an advanced playlist of the terms maybe in more detail/other ones would be great :) love learning concepts which like you say are not syntax/prog_lang specific.. act learning the blueprints so to speak of how and why it works
@monireachtang712 Жыл бұрын
Very clear and easy to understand! Thank you for sharing.
@devworks8787 Жыл бұрын
This is the proper video for memoization explained for Python while most use the Fibonacci example
@roy67876 жыл бұрын
Holy Moly! Thanks for that, bro. Really helps me optimized my program!
@theartist88355 жыл бұрын
A very beautiful playlist ❤️ do more of these please. They're so useful
@techfornoobs42417 жыл бұрын
This is an awesome explanation. thank you so much!
@davidm.johnston89947 жыл бұрын
I love you man, your videos are just so useful and easy to understand. Thanks
@robinfrancis99148 жыл бұрын
You are a great teacher!!
@darshanmm97 жыл бұрын
Hi Corey I become your fan! i never seen anyone teach with such clearity on youtube😊👍
@petarkolev69286 жыл бұрын
Yes, he does it very well! But checkout FunFunFunction channel as well if you are in to JavaScript ofc :)
@maxim92805 жыл бұрын
At last a clear cut explanation.
@kesh45054 жыл бұрын
best explanation !
@lisandrofilloy51264 жыл бұрын
Great work Corey!
@wouterspelt3 жыл бұрын
Clear explanation! Thanks.
@krishnar99325 жыл бұрын
Simplified explanation. Thanks
@captainmash-h8h4 жыл бұрын
very clear and clean explanation, thanks!!!
@navjotmannan73035 жыл бұрын
Awesome explanation!!
@anim31973 жыл бұрын
Very well explained. Thank you!
@ryan-tabar2 жыл бұрын
# You can turn the process into a decorator so you can add it to any function def memoization(original_function): cache = {} def inner_function(arg): if arg in cache: print(f"Result was retrieved from cache.") return cache[arg] else: print(f"Memoizing result of function {original_function.__name__}({arg}).") cache[arg] = original_function(arg) return cache[arg] return inner_function @memoization def square(number): return number ** 2
@samwilliams40245 жыл бұрын
Huge fan of your videos Corey! The functools.lru_cache decorator is also a great way to implement memoization on functions.
@jonathanwhite27155 жыл бұрын
Thanks. Easy to understand
@charlesokoyoh5 жыл бұрын
Thank you Corey
@smallblueflower7 жыл бұрын
You're videos are great! Thank you!
@hustels8 жыл бұрын
Amazing tutorials.
@sairajdas66926 жыл бұрын
Excellent video
@MaxS-v7x7 жыл бұрын
Thank you for your work, perfectly explain!
@futurestar10008 жыл бұрын
such smooth explanation corey \/
@dipankararora26335 жыл бұрын
your videos are too good.
@abuyusufansari66207 жыл бұрын
Thank you for this nice explanation.
@hubertcombomarketing26934 жыл бұрын
Good as always. Thanks.
@wartem2 жыл бұрын
This is brilliant
@luizfelipels73 жыл бұрын
Such a fancy name for a simple idea.
@Lahiru_Udana5 жыл бұрын
Thanks for the great video
@quinnwang69293 жыл бұрын
Great presentation. Is it okay to use "list" instead of "dictionary" in the ef_cache? Thx.
@antoniosaqueton32934 жыл бұрын
Hope you can come up with tutorials on data structures or at the least, recursion. Please help a brother out!
@TheTruthFadeswithTime286 жыл бұрын
Can you do a video on recursion ?
@Leonardo-jv1ls3 жыл бұрын
When I have a doubt about anything in this world, i go to youtube and write "corey schafer +anything". If not found, i quit of learning it.
@pythoninnovate24288 жыл бұрын
Like your videos on Python ... Quick query on this video: Im a beginner so a very simple query though: How did you get the time of the overall execution of the program, i mean 4.0s or 2.0s in this video? Any inputs on how to get it in 'pycharm' will be helpful.
@DarkOceanShark3 жыл бұрын
Hello, are you able to do it now (5 years)?
@khireddinebelkhiri7255 жыл бұрын
thank you thank you thank you
@VictorSantos-yb8ir3 жыл бұрын
Thanks!
@obed8182 жыл бұрын
Hello if you plan to use it i suggest you to check this video more up to date 👍 kzbin.info/www/bejne/ep-uqX58jadnhLM
@augiblutz28522 жыл бұрын
well done
@jean-michelcid95944 жыл бұрын
amazing!!!!
@maxim92805 жыл бұрын
But this only seems useful when you've multiple calls of the same function with the same arguments. My point is, what could this possibly be for in a program? In many applications a function is called as many times as the program itself is called. But the cache gets cleared anyway. Could this method be used here?
@boggeshzahim37135 жыл бұрын
I'm sure it has uses outside the classroom... somewhere
@obed8182 жыл бұрын
this comment is old but ill add my touch, this exemple is the best by mcoding and you will maybe appreciate the decorator trick, in recursive call it can get useful kzbin.info/www/bejne/ep-uqX58jadnhLM
@bernoulli90475 жыл бұрын
If you're looking to make an intermediate series of videos, memoization using Python 3's functools.lru_cache would be pretty cool.
@rohanpednekar80744 жыл бұрын
Great !
@Usammityduzntafraidofanythin6 жыл бұрын
Shouldn't the block after the if in the expensive function still execute after the if executed, even if there is a value put in that matches what's in dictionary?
@chengguanpropertysg91404 жыл бұрын
The result is returned in the if block
@ashishkumarnath12594 жыл бұрын
You are god!!!!, thank you so much!
@snoopyjc5 жыл бұрын
How are you using “print” without () ?
@yashrajvanshi175 жыл бұрын
That program was written in Python 2.X version not in Python 3
@ziqb4 жыл бұрын
All my life, I had been calling it caching ..
@poorna6854 жыл бұрын
i thought he would explain about lru_cache
@stevendye2497 жыл бұрын
Why don't we need an else statement after the if statement in expensive_func?
@coreyms7 жыл бұрын
Because if it runs the code in the "if" statement then it will just immediately return... so you don't need the else statement because the code after the "if" won't be run anyways if the conditional is met. Hope that makes sense.
@sodapopinski99226 жыл бұрын
then why do we need else statements. if the program meets the conditional it breaks after the return, if not it runs the rest of the code
@ultiumlabs48996 жыл бұрын
it is actually Corey's style. you could use different style and use else statement to get the same result. in the if block: just assign the result to result variable. if num in ef_cache: result = ef_cache[num] else: print('') time.sleep() ef_cache[num] = num*num result = num*num return result
@MrBrainOwl7 жыл бұрын
Perfect!!!
@kavitatoragal29114 жыл бұрын
How do you show the time spent [Finished in _s]? Is it some configuration?
@vasudev161804 жыл бұрын
It will show you automatically In the sublime text editor
@hsabrey5 жыл бұрын
how to show that command says [Finished in 4.0s], i did not find it in vsCode, appreciate your help.
@chrishau61787 жыл бұрын
Will the caching still work if you import the function into a separate program?
@coreyms7 жыл бұрын
Yes, that should still work.
@johnc74364 жыл бұрын
Good
@abinash1387 жыл бұрын
what is the use of sleep in this program
@coreyms7 жыл бұрын
Sleep just pauses the execution for a bit so that we can simulate the time it might take to compute a more intensive function
@mymantra43 жыл бұрын
Plz zoom the code
@adrianmoscovciuc42974 жыл бұрын
Nice video Corey, thx for teaching us all this info. For all of you that need and example of the memoization used, you can reffer to the Socratica video on fibonacci sequence: kzbin.info/www/bejne/h5yTq4iQjJKIla8 , with those two videos you will be able to understand better the concept.
@pipboy2145 жыл бұрын
Maybe your video is good for a first grasp of the term, and you could say thats the point, but memoization is also a technique that doesn't need an external data structure to work, i sugest you to read and maybe talk about it, cause nobody wants dirty globals or spaghetti oriented programming, when You can implement a memoized pure function.
@jiernade4585 Жыл бұрын
Last minute assignment anyone? xd
@connormichalec4 жыл бұрын
I came hear to learn how to pronounce the word
@_slier4 жыл бұрын
Im just gonna save ur time..Memoization is purely caching...
@karimmoradi2003 Жыл бұрын
As always, very nice explanation Corey, Thanks. What about using functools.cache decorator?