The Single Most Useful Decorator in Python

Поділитися
Вставка
  • Опубліковано 11 гру 2020
  • The most useful decorator in Python is @cache.
    It's from the functools library (and a similar variant called @lru_cache too). This decorator was introduced in Python 3.9, but lru_cache has been available since 3.2. Often times, the cache decorator can be used to automatically do dynamic programming algorithms.
    ― mCoding with James Murphy (mcoding.io)
    Source code: github.com/mCodingLLC/VideosS...
    SUPPORT ME ⭐
    ---------------------------------------------------
    Patreon: / mcoding
    Paypal: www.paypal.com/donate/?hosted...
    Other donations: mcoding.io/donate
    BE ACTIVE IN MY COMMUNITY 😄
    ---------------------------------------------------
    Discord: / discord
    Github: github.com/mCodingLLC/
    Reddit: / mcoding
    Facebook: / james.mcoding
  • Наука та технологія

КОМЕНТАРІ • 774

  • @GuilhermeFArantesSouza
    @GuilhermeFArantesSouza 3 роки тому +2503

    You're telling me I've been manually coding caches unnecessarily? That's what you get by relying on your decade old knowledge of C in Python.

    • @mCoding
      @mCoding  3 роки тому +353

      Sometimes I forget and write one anyway!

    • @senku3288
      @senku3288 3 роки тому +92

      now i wanna know how you code cache

    • @mmanuel6874
      @mmanuel6874 3 роки тому +18

      @@senku3288 me too

    • @diegosolis9681
      @diegosolis9681 3 роки тому +62

      This happens to me too much to comfort.
      I started coding in python when there was the 2 version. Some years go by and now there's python 3 and I start to learn it and find myself with so many things that are different and so many new stuff that's cool but I never heard of it.
      It's annoying to know that things you spent a lot of time on learning are now really simple to use/implement thanks to libraries and such. It's a blessing for newcomers, a torment for old timers.

    • @SumEpithet
      @SumEpithet 3 роки тому +83

      @@senku3288 They probably use dynamic programming methods: Creating a data structure to store solutions and call it before doing work to see if that work is necessary before retreading old ground. The caching and its efficiency will then be determined by if you made sure to consider how that data is being accessed to take advantage of cache lines.

  •  3 роки тому +645

    There is one BIG WARNING: Use this only on pure functions (without side effects)!
    @cache does not run the function but only returns its value so if you for example write to a file in that function, the file write will not happen if the cache is evoked.

    • @Slada1
      @Slada1 3 роки тому +110

      If you want clean code, use 2 types of functions. 1) functions with side effects that return nothing, 2) functions without side effects that return values. Then you will know, that you can call the function safely anytime, if it returns value.

    • @quinndirks5653
      @quinndirks5653 3 роки тому +12

      It has to run the function at least once to know what the value is for that input, right? So a file write would happen on the first run. That also means that if a function return value is supposed to be random, cache would cause it to not be random. Right?

    • @Slada1
      @Slada1 3 роки тому +4

      @@quinndirks5653 usually all "random" functions are only pseudorandom. They are seeded usually with time

    • @quinndirks5653
      @quinndirks5653 3 роки тому +30

      @@Slada1 Irrelevant to my question. I know how they are seeded and I know they are only pseudorandom. Read my first comment again for context. I'm thinking that if you put @cache on a random number generator for instance, @cache would cause it to always return the same number, right? I'm imagining that @cache stores the return value for a given input, so if you call rand() several times in a row, it runs it once to get the return value, stores the return value for the given input, which is nothing in this case, and subsequent calls to @cache rand() will cause it to return whatever the random number was the first time it ran. Right? Or wrong?

    • @quinndirks5653
      @quinndirks5653 3 роки тому +3

      @@Slada1 O.P. does say "if cache is evoked" meaning O.P. knows that the function has to run at least once to get the return value, which means that the write would happen. And it's only subsequent calls where the write wouldn't happen, once the cache is being evoked. Unless cache works in a different way than I'm suspecting, I think I'm right about random function becoming non-random with the use of @cache.

  • @TheZethera
    @TheZethera 3 роки тому +1581

    I did not know python had automatic memoization. Thank you for this knowledge.

    • @mCoding
      @mCoding  3 роки тому +155

      You are very welcome! There are some other related tools you may like to read up on in the functools library.

    • @JiffyJames85
      @JiffyJames85 3 роки тому +28

      I've written my own memorization decorator so many times. It simple. But having a built-in in one is awesome.

    • @hachiesamor6648
      @hachiesamor6648 3 роки тому

      ⁰⁰⁰

    • @wannabedev2452
      @wannabedev2452 3 роки тому +10

      Just few days ago i solved a kata on codewars which had this exact problem
      I wish i knew this at that time
      I used a txt file to store the results 🤣

    • @laurinneff4304
      @laurinneff4304 2 роки тому +5

      @@wannabedev2452 an easier way to implement it yourself is to store a dict with the arguments as keys and if you have multiple args, put them in a tuple

  • @evanchong762
    @evanchong762 3 роки тому +65

    If anyone was wondering; if you'd like to invalidate the cache you could do (for this example) `fib.cache_clear()`.

    • @mCoding
      @mCoding  3 роки тому +2

      Thanks for sharing this tip!

  • @Soul-Burn
    @Soul-Burn 3 роки тому +442

    Another very useful related decorator is "cached_property", which lets you compute a property just once when needed, and remember it as long as the object exists.

    • @mCoding
      @mCoding  3 роки тому +85

      Thanks for pointing this out! This is also in my top 10 most useful decorators!

    • @W0TAN
      @W0TAN 3 роки тому +64

      @@mCoding Will you make a video to those top 10? This video already blew my mind, I'd love to have some more of that hidden knowledge!

    • @Sh-hg8kf
      @Sh-hg8kf 3 роки тому +5

      Python noob here. What's the difference between cached property and what was used here?

    • @Soul-Burn
      @Soul-Burn 3 роки тому +3

      That's it's a property rather than just a function/method.

    • @najarvis
      @najarvis 3 роки тому +6

      How is a cached property different from a normal variable?

  • @StarNova9
    @StarNova9 3 роки тому +221

    I'm amazed, when I saw this my first thought was THERE'S NO WAY. Such a big improvement with so little effort is rare to see! Thanks a lot for sharing!

    • @mCoding
      @mCoding  3 роки тому +9

      Thank you! Cheers!

    • @koktszfung
      @koktszfung 3 роки тому +3

      it uses much more memory if not lru_cache

  • @phillec5084
    @phillec5084 3 роки тому +50

    It's rare that video whose title contains a superlative actually lives up to the expectations. Great job!

    • @mCoding
      @mCoding  3 роки тому +6

      Glad you liked it!

    • @Redditard
      @Redditard 2 роки тому

      @@mCoding :) LOL (lots of love)

  • @jonasls
    @jonasls 3 роки тому +26

    Audio tip for the future: Boost the high frequencies (+18 dB) with a high shelf at starting around >3 kHz, or low Q (0.5) bell at 7.5 kHz to make your voice a lot more clear. Big difference. You can probably do this in any video editing software.
    PS: loved this vid

    • @mCoding
      @mCoding  3 роки тому +13

      I'm such a noob at video editing! Thanks for the tip.

    • @jonasls
      @jonasls 3 роки тому +3

      @@mCoding Don't worry, great videos. Just thought the audio was a bit unclear :) Bringing back some high frequencies should do it.

  • @asad-ullahkhan2368
    @asad-ullahkhan2368 3 роки тому +230

    Wanted to add that if your function returns a mutable object (eg list) and you then modify that value, you are modifying the return value of the cache, making all future calls return the modified object. You need to make a copy of the object before using it (or do not modify it in the first place).

    • @mCoding
      @mCoding  3 роки тому +50

      Thanks for pointing out this gotcha that we need to watch out for!

    • @user-hk3ej4hk7m
      @user-hk3ej4hk7m 3 роки тому +9

      Returning immutable objects is the best option, that or either composing the cached function with copy.deepcopy like ``copy.deepcopy(my_cached_fun(args))``, probably using another decorator would be the most pythonic way.

    • @jorgeestebanmendozaortiz873
      @jorgeestebanmendozaortiz873 3 роки тому +23

      Which is why these decorators are included in "functools": they will only reliably work from a functional programming point of view, which excludes mutable objects.

    • @ko-Daegu
      @ko-Daegu 3 роки тому +1

      @@jorgeestebanmendozaortiz873
      thankx for info
      but could you explain what he meant by:
      "You need to make a copy of the object before using it"1
      how so in real example it will look like

    • @NateROCKS112
      @NateROCKS112 3 роки тому +3

      @@ko-Daegu just make a copy of any list returned. You can do this either with "list.copy()" or with the idiom "list[]."

  • @FallinPython
    @FallinPython 3 роки тому +135

    This is in fact an incredible tip!
    4 minutes of video, direct to the point and a life saver =)

    • @mCoding
      @mCoding  3 роки тому +5

      Glad it was helpful!

  • @maheenmashrur2574
    @maheenmashrur2574 3 роки тому +56

    I literally jumped from my chair when I saw how fast cache made the function.
    Thank you for sharing such a useful knowledge.

    • @mCoding
      @mCoding  3 роки тому +3

      You're welcome!

  • @normalmighty
    @normalmighty 3 роки тому +49

    I can't believe I manually coded a cache just a few weeks back when this was a thing in python the whole time.

    • @MagnumCarta
      @MagnumCarta 3 роки тому +2

      It's still a good idea to know *how* a cache is designed (e.g. for whiteboard interviews).

    • @laurinneff4304
      @laurinneff4304 2 роки тому +5

      @@MagnumCarta in case someone wants to know, basically like this:
      cache = dict()
      def func(arg):
      if arg in cache:
      return cache[arg]
      ret = ...
      cache[arg] = ret
      return ret
      And turn the keys into tuples if you have multiple args

  • @Caspitein
    @Caspitein 3 роки тому +62

    Built-in memoization, that's so cool! Thanks for sharing!

  • @chigozie123
    @chigozie123 3 роки тому +18

    I can see someone using this cache decorator in a real product, forgetting that it does not evict cached items from memory, then they start running out of memory and wondering why.
    You are better off using lru_cache with a size limit and only do it if your function is actually called with values that can be reused in the next calls to the function

    • @mCoding
      @mCoding  3 роки тому +4

      Good point! I should have warned about this in my video!

    • @CFEF44AB1399978B0011
      @CFEF44AB1399978B0011 5 місяців тому

      I can also see someone using this to cash items for my function that isn't actually side effect free and then getting all sorts of corruption, or using this in returning items like lists which are mutable and then having all sorts of hell happen.

  • @fakename45
    @fakename45 Місяць тому

    I would just like to say that I discovered this channel a couple of days ago.
    Your videos are incredibly helpful... thank you for the uploads, you have a new subscriber (and I will be binge watching your videos this weekend).

  • @valtimyrio
    @valtimyrio 3 роки тому +4

    Man your channel is really helpful,
    Thanks for work!

    • @mCoding
      @mCoding  3 роки тому

      Happy to help!

  • @Ezechielpitau
    @Ezechielpitau 3 роки тому

    Did not know that. I really like the length too. Short, straight to the point. Very valuable, subscribed :)

  • @ElSenorEls
    @ElSenorEls 3 роки тому +30

    This video is going to blow up. It is super useful, time-saving, short and "yt algo friendly".

    • @mCoding
      @mCoding  3 роки тому +6

      Glad it was helpful!

    • @ElSenorEls
      @ElSenorEls 3 роки тому +1

      @@mCoding I've to thank you. I've learned something new yesterday and today. Without people like you, UA-cam would just be shitposts lol

  • @bossotron1935
    @bossotron1935 3 роки тому +1

    Found this channel recently, very clear and great examples!

    • @mCoding
      @mCoding  3 роки тому

      Glad you think so!

  • @wreynolds1995
    @wreynolds1995 3 роки тому

    Short, to-the-point, extremely useful. I watched this one video from your channel and subscribed immediately afterwards.

    • @mCoding
      @mCoding  3 роки тому

      Awesome, thank you!

  • @josephlyons3393
    @josephlyons3393 3 роки тому +11

    I knew from the thumbnail of this video (seeing the fib function), that you were going to go over the cache decorator. It is also my favorite decorator! Although, I never really get to use it in production code, as I mostly use it with recursive functions and we try to avoid recursion in our codebase.

    • @mCoding
      @mCoding  3 роки тому

      Glad you have the same favorite!

    • @danielmitre
      @danielmitre 2 роки тому +2

      It can be useful in non-recursive functions to avoid extra latencies in common requests or whatever expensive computation (just notice you're a rustacean too yayy :) )

  • @brock2k1
    @brock2k1 3 роки тому

    This is a perfect little video. Short, clear, and very useful. Thank you.

    • @mCoding
      @mCoding  3 роки тому

      Glad you enjoyed it!

  • @bgill7475
    @bgill7475 3 роки тому

    This is awesome. Thank you so much!
    I had no idea about this before.
    Your videos are amazing by the way.

    • @mCoding
      @mCoding  3 роки тому

      Happy to help!

  • @Misterblackh0l3
    @Misterblackh0l3 3 роки тому +1

    You are amazing. Short and to the point!!
    You earned my sub. Thank you.

    • @mCoding
      @mCoding  3 роки тому

      Thanks for the sub!

  • @staticchimera44
    @staticchimera44 6 місяців тому

    Thanks so much for this video! I was trying to compute a highly intensive recursive function and I had never heard of this!

  • @the-nasim
    @the-nasim 3 роки тому

    That's really cool, subscribed 😊

  • @mmanuel6874
    @mmanuel6874 3 роки тому +1

    I love how you reply to all comments. Even though I've been using python for some years I'm still learning valuable material

    • @mCoding
      @mCoding  3 роки тому

      I try but now there's way too many for me to get to!

  • @anthonytam5633
    @anthonytam5633 2 роки тому

    This channel is awesome man. Thanks for this

  • @_Sizzin
    @_Sizzin Рік тому

    This is very useful, I didn't know about it. Thank you for sharing it!

  • @eoghainlebioda1396
    @eoghainlebioda1396 3 роки тому

    This is amazing :D I'd LOVE to see more videos like this :D

  • @jlmknight
    @jlmknight 2 роки тому

    Neat, at first I thought it would only be half as fast. Very efficient, thanks!

  • @typedeckeralt7628
    @typedeckeralt7628 3 роки тому +1

    Thankyou so much this was exactly what I was looking for! this seems this to help speed up stuff in pure python without numba or cython.

    • @mCoding
      @mCoding  3 роки тому

      You're very welcome!

  • @2Sor2Fig
    @2Sor2Fig 3 роки тому +7

    I find it so interesting how we approach coding differently. Whilst I've used the @cache decorator, this isn't somewhere I've ever thought to use it. My immediate thought would have been to create a generator function. Now that I think about it, though, this is much more concise. If you wrote this as a generator then each time you computed fib(n-1) you would have to store it in some variable ( for the sake of providing a concrete example, call that variable "last_fib" and assume that it is only declared within the scope of the generator function). Then the next time the generator is called, it substitutes "last_fib" for fib(n-2) ... This is much simpler.

  • @sjfas_
    @sjfas_ 3 роки тому

    This got recommended to me, and wow this is actually really useful
    Thanks man

    • @mCoding
      @mCoding  3 роки тому

      Glad to hear it!

  • @casperschutte2516
    @casperschutte2516 2 роки тому

    I cannot believe the amount of useful info you have on your channel. Many thanks, brother

    • @mCoding
      @mCoding  2 роки тому +1

      You are most welcome!

  • @lior_haddad
    @lior_haddad 3 роки тому +1

    That's a great tip, thanks for sharing!

    • @mCoding
      @mCoding  3 роки тому

      Glad it was helpful!

  • @jonastencate4612
    @jonastencate4612 3 роки тому

    Wow this is amazing, thanks man!

  • @ChrisHalden007
    @ChrisHalden007 3 роки тому

    Wow. Love it. Great video. Thanks!

    • @mCoding
      @mCoding  3 роки тому

      Thank you too!

  • @saisagarsingh3340
    @saisagarsingh3340 Рік тому

    Great stuff man 👍

  • @josepht3262
    @josepht3262 3 роки тому

    This is very useful. Thank you!

    • @mCoding
      @mCoding  3 роки тому

      You're welcome and thanks for watching!

  • @yesveryprofesionalnameyes6055
    @yesveryprofesionalnameyes6055 3 роки тому +7

    alternate title: a 4 minute video that just completely makes dynamic programming useless in python

    • @davidwuhrer6704
      @davidwuhrer6704 3 роки тому

      It's just a more elegant way to do dynamic programming.

  • @kartikjha833
    @kartikjha833 3 роки тому

    MIND BLOWN. Amazing content.

  • @rara4
    @rara4 3 роки тому +1

    Blown away. Awesome !

  • @Kattemageren
    @Kattemageren 2 роки тому

    That is very cool, thanks!

  • @namsejin
    @namsejin 3 роки тому

    This was very useful. You got a new subscriber.

    • @mCoding
      @mCoding  3 роки тому

      Awesome, thank you!

  • @xkhokokox
    @xkhokokox 3 роки тому +2

    Yup this is quality content. Subbed!

    • @mCoding
      @mCoding  3 роки тому

      Much appreciated!

  • @BosonCollider
    @BosonCollider 3 роки тому +5

    Okay, the cache thing was known to me and is just a time vs memory tradeoff, but the LRU cache is fucking genius

  • @DominikJagoda
    @DominikJagoda 7 місяців тому

    Thanks, very helpful decorator

  • @medtay8808
    @medtay8808 3 роки тому +7

    this is precious
    how didn't i learn about this sooner

    • @mCoding
      @mCoding  3 роки тому +2

      You're welcome!

  • @samuelfeder9764
    @samuelfeder9764 2 роки тому +1

    Amazing Video!

  • @alexandrewatrin8293
    @alexandrewatrin8293 3 роки тому

    This is life changing omg thank you!

    • @mCoding
      @mCoding  3 роки тому

      Glad it helped!

  • @jay89boy
    @jay89boy 3 роки тому

    Thank you for helping us :) great content

    • @mCoding
      @mCoding  3 роки тому

      Happy to help!

  • @raphaelmapp8407
    @raphaelmapp8407 3 роки тому

    Just found this channel. Great topics, excellently explained.

  • @MattOatesUK
    @MattOatesUK 3 роки тому +6

    Those of you on older Python without an explicit @cache you can use @lru_cache(None) the explicit None means cache all the things forever

  • @albogdano
    @albogdano 3 роки тому +48

    Thank you, and thanks to youtube algorithm for bringing me here.

    • @mCoding
      @mCoding  3 роки тому +1

      Thanks for coming!

    • @fat_pigeon
      @fat_pigeon 3 роки тому

      Yo dawg, I heard you like algorithms so I used an algorithm to send you an algorithm....

  • @NicoSmets
    @NicoSmets 2 роки тому

    That's pretty powerful! And it allows you to keep you code elegant and readable.

  • @veziop
    @veziop 3 роки тому

    wow that's actually amazing! i oughta try it out

  • @thedoublehelix5661
    @thedoublehelix5661 3 роки тому +1

    This is great! I think I'm going to make a version of this for c because it's so useful

  • @BlackHermit
    @BlackHermit 3 роки тому

    Very nice, I never heard of this one before. Thanks!

    • @mCoding
      @mCoding  3 роки тому

      Glad you like it!

  • @bombi012
    @bombi012 2 роки тому +1

    This is awesome! I love your videos! New subscriber here! :D

    • @mCoding
      @mCoding  2 роки тому

      Welcome to the club!

  • @tstone9151
    @tstone9151 3 роки тому +6

    Dude, I love you for this, you just saved me lol

    • @mCoding
      @mCoding  3 роки тому

      Thanks! You're welcome!

  • @jamesbrown8766
    @jamesbrown8766 3 роки тому

    Fantastic tip! Thanks!

  • @stevebob240
    @stevebob240 3 роки тому

    That's beautiful, very helpful.

    • @mCoding
      @mCoding  3 роки тому

      Thank you! Cheers!

  • @linear9185
    @linear9185 3 роки тому +2

    holy shit this is so useful tysm for making these videos

  • @entropy7571
    @entropy7571 3 роки тому +4

    Somehow, I knew about this decorator, and also about memoisation in dynamic programming, but it never clicked that they're the same thing. So I was still implementing my own caches for DP

  • @adrianbratt9927
    @adrianbratt9927 8 місяців тому

    Fantastic. Thank you so much.
    A.

  • @stjepandrenski5486
    @stjepandrenski5486 3 роки тому +1

    Amazing, thanks for sharing

    • @mCoding
      @mCoding  3 роки тому

      Thanks for watching!

  • @javiercmh
    @javiercmh 3 роки тому

    How did I not know about this!? Thanks a lot!

  • @judahschwartz7459
    @judahschwartz7459 2 роки тому

    Nice! Thanks

  • @SGTkrusha
    @SGTkrusha 3 роки тому +2

    This is absolutely brilliant how did I not know this existed

  • @hyperionspring6529
    @hyperionspring6529 3 роки тому

    Amazing content :D subbed and liked

    • @mCoding
      @mCoding  3 роки тому

      Much appreciated!

  • @SMANahian
    @SMANahian 2 роки тому

    Wow this is very useful!!

  • @amaarquadri
    @amaarquadri 3 роки тому

    This is beautiful!

  • @kevinmontero4158
    @kevinmontero4158 3 роки тому

    Learned something useful today, thank you. No need to create another dict for memoization

  • @Xaminn
    @Xaminn 3 роки тому

    Wow. Seeing the speed difference is remarkable. Thanks for the explanation.

    • @mCoding
      @mCoding  3 роки тому

      Glad it was helpful!

  • @awalstreetjournal
    @awalstreetjournal 3 роки тому +1

    Hey this is amazing, thank you.

    • @mCoding
      @mCoding  3 роки тому

      You're welcome!

  • @wasiuyahya1427
    @wasiuyahya1427 2 роки тому

    Great. Thank you.

  • @iainsaunders6983
    @iainsaunders6983 3 роки тому +3

    Just a note for those who tried cache and it didn't work for them, try lru_cache instead, eg: @lru_cache(maxsize=5)
    cache seems to have been added in Python 3.9, but lru_cache looks to have been added since 3.2.
    Great video by the way, really easy to follow and start using the code myself!

  • @gaby1491
    @gaby1491 3 роки тому

    this is great! Thank you

    • @mCoding
      @mCoding  3 роки тому +1

      Glad you liked it!

  • @prianshu1995
    @prianshu1995 3 роки тому

    Amaazzzing 😱..
    Thanx a lot for such a useful tip.
    although i am a beginner and don't understand this as deeply but this made me instantly subscribe to your channel. 😁

  • @vxsniffer
    @vxsniffer 3 роки тому

    works like magic, thanks ;-)

  • @Mertly
    @Mertly 3 роки тому +8

    I'm pretty new to Python, I think more people should know about this

  • @nicknick65
    @nicknick65 3 роки тому

    fantastic - thanks for that

    • @mCoding
      @mCoding  3 роки тому

      Glad you enjoyed it

  • @shravilpotdar
    @shravilpotdar 3 роки тому

    Mind blowing tip bro. This means we don't have to optimize our code using DP

    • @mCoding
      @mCoding  3 роки тому

      Glad you liked it!

  • @nikolastamenkovic7069
    @nikolastamenkovic7069 Рік тому

    Your videos are gems!

  • @HDQuote
    @HDQuote 3 роки тому

    This is amazing!

  • @piotrszocik7775
    @piotrszocik7775 3 роки тому +1

    really interesting, subscribed for more :)

    • @mCoding
      @mCoding  3 роки тому +1

      Awesome, thank you!

  • @haroldpepete
    @haroldpepete 3 роки тому

    great tip, thank for share

  • @Ikkalyzte
    @Ikkalyzte 2 роки тому

    First time I've seen a title like this that's not clickbait. Thanks for helping out us occasional Python users

  • @matiasm.3124
    @matiasm.3124 2 роки тому

    Awesome !

  • @Sahil_Shukla98
    @Sahil_Shukla98 3 роки тому

    Great video!

  • @darcipeeps
    @darcipeeps 14 днів тому

    What an awesome line of code. Life hack for dynamic programming interview questions 😂

  • @Mr-vy7zf
    @Mr-vy7zf 2 роки тому

    I remembered one video about making a mandelbrot set being displayed using Pygame with different methods (using original code; numpy; numba, taichi...) ((it was a RUS video but nevertheless)), and it gave awesome results with some Numba Parallel computations, but then I tried applying lru_cache to it just today, and on identical render settings it jumped from ~30 to ~200 FPS as I added the decorator to the update function/method, which is quite interesting to observate

  • @someaccount3438
    @someaccount3438 3 роки тому

    Glad I found this channel.

  • @DimaZheludko
    @DimaZheludko 3 роки тому

    Wow. Amazing. Python is such well-thought language.
    Now I'll have to look up all my projects at put cache everywhere.

    • @igorthelight
      @igorthelight 3 роки тому

      Just be aware of UNSANE memory usage increase!
      Use lru_cache() with low "maxsize" value (start from 1 and go upward)

  • @tuttifrutti8172
    @tuttifrutti8172 3 роки тому

    This is the second video of yours I've watched and I feel obligated to subscribe

  • @neetsmlam
    @neetsmlam 2 роки тому

    nice! thanks!

  • @aman31dec
    @aman31dec 2 роки тому

    Big fan after seeng this video. Keep sharing such important python hacks.

  • @dragonsage6909
    @dragonsage6909 2 роки тому

    Wow, in under 4 minutes, you given me back many hours of my life.. you are a wizard. :)
    Thank you!

  • @ProtonChicken
    @ProtonChicken 3 роки тому

    Wow I had no idea you could do this, absolutely blew my mind