Recursion, the Fibonacci Sequence and Memoization || Python Tutorial || Learn Python Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 687

  • @Socratica
    @Socratica  2 ปีที่แล้ว +8

    Wear a Socratica Python shirt for good luck coding: shop.socratica.com/products/python-by-socratica

  • @Socratica
    @Socratica  5 ปีที่แล้ว +191

    It's official! The Socratica Python Kickstarter was a success! Thank you to all of our supporters. Because of you, many more Python videos coming soon!! 💜🦉

    • @inamullahkhan4748
      @inamullahkhan4748 5 ปีที่แล้ว +2

      i am waiting for your videos

    • @longLivejay1
      @longLivejay1 4 ปีที่แล้ว +2

      Can you make a video on oop in Python pls ???

    • @ukaszxyz5689
      @ukaszxyz5689 4 ปีที่แล้ว +2

      @@longLivejay1 Yes! I too want OOP Python!

    • @vasuudayar3691
      @vasuudayar3691 4 ปีที่แล้ว

      can u plz make video more on algo

  • @AndrewErwin73
    @AndrewErwin73 5 ปีที่แล้ว +136

    "People love to debate the smallest of details." Understatement of the 21st century!

  • @maryz.r.avecilla4788
    @maryz.r.avecilla4788 4 ปีที่แล้ว +56

    I love Socratica's voice, honestly, she does have a clear, direct, cogent voice and excellent pronunciation. I truly love and enjoy your videos.

    • @Socratica
      @Socratica  4 ปีที่แล้ว +9

      You are so kind, thank you! We're so happy you're watching!! 💜🦉

  • @Zelliana
    @Zelliana 8 ปีที่แล้ว +182

    I laughed so hard when she said "Frustrating... I know" with her kind of robotic tone XDDDDD

  • @random-604
    @random-604 4 ปีที่แล้ว +26

    Just found this channel via a youtube recommendation. Wow. Such high quality editing, voiceover, code quality, code clarity, and conciseness. I can't believe this video is almost 4 years old and I've only just discovered it. Subscribed!

  • @rasheddoha4213
    @rasheddoha4213 7 ปีที่แล้ว +15

    These are hands down the best Python tutorials on the internet. I've been looking for a quick refresher after a 5 year break from writing python and these are amazing. I'm definitely recommending these to students in the future.

    • @devworks8787
      @devworks8787 ปีที่แล้ว

      wow me too learning Python again after 5 years of break.

  • @rafaelperes6333
    @rafaelperes6333 5 ปีที่แล้ว +7

    That deadpan delivery makes this learning experience the best I've ever had.

  • @elysel9424
    @elysel9424 7 ปีที่แล้ว +396

    i dig the dry humor

    • @roydm100
      @roydm100 4 ปีที่แล้ว

      sooo true

    • @asmodeus4310
      @asmodeus4310 3 ปีที่แล้ว

      Did you create the lambda function ahhahahahhahha

    • @itsme7570
      @itsme7570 3 ปีที่แล้ว

      I know I love her! I'm addicted

  • @Socratica
    @Socratica  5 ปีที่แล้ว +6

    Support what you love! Socratica has a Kickstarter to make more Python: bit.ly/PythonKickstarter

  • @tyrisnolam
    @tyrisnolam 7 ปีที่แล้ว +103

    I came here frustrated over a programming assignment but your tone is very calming. Clear explanation, thank you so much for your work!
    Could you please make a video using the yield statement as well?

  • @priyankashah9786
    @priyankashah9786 5 ปีที่แล้ว +26

    I was suffering while watching many python tutorials with silly examples and incomplete logic explanation. I used to feel that if this is called machine learning then no wonder we are producing the most stupid machines. those tutorials made me feel that higher education is cheating the labor class with only jargonizing tech. But when I watched you socratica I felt that there is some meaning, some enlightenment in learning Python. If this is engineering then it deserves to be paid a higher salary. If this is machine learning, then it makes sense to use it.
    Loved it. Would love to know who you are. You are producing a ray of light in the darkness of tech world.
    Most beautiful thing is your name. I loved Socrates for the beautiful intelligence he shared with the world and what could be more powerful name for a feminine intelligence to bring equality of respect for women in tech!

    • @Socratica
      @Socratica  5 ปีที่แล้ว +3

      Thank you for your very kind message. We love what we do and it really is a labour of love, but it's also wonderful to hear from someone who values our work. 💜🦉
      You can learn more about our small team here: www.patreon.com/socratica

  • @emperor8716
    @emperor8716 7 หลายเดือนก่อน +1

    Optimization is beautiful. The difference of speed between the before and after is insane.

  • @mayureshharihar2557
    @mayureshharihar2557 ปีที่แล้ว +1

    Way of teaching is unique and effective. Thank you....

  • @shreehari2589
    @shreehari2589 3 ปีที่แล้ว +6

    Netflix : meh
    Socratica : all day every day!!!! ❤️
    Thank you very much for the tutorials

  • @Socratica
    @Socratica  5 ปีที่แล้ว +41

    Welcome to Socratica! You can see our entire Python Playlist here: bit.ly/PythonSocratica
    Subscribe to see all our new videos! bit.ly/SocraticaSubscribe

    • @joel9909
      @joel9909 4 ปีที่แล้ว +1

      Waoo just fell on here. I love the channel already. Looks like an AI from Mars is teaching me. It's out of this world really. Subscribed already

    • @theeiszeitmann928
      @theeiszeitmann928 4 ปีที่แล้ว +1

      The issue with recursion is, that you must understand recursion before you can understand recursion.

  • @shubhamgaurav7094
    @shubhamgaurav7094 6 ปีที่แล้ว +1

    that little humor...robot-like accent...amazing background sound effects...this is unbeatable

  • @jeremygiaco
    @jeremygiaco 5 ปีที่แล้ว

    This function i whipped up seems pretty quick. This is fun stuff to play with to learn python! Thanks for the video!
    # this returns the nth fibonacci sequence quickly
    def fib(nth: int, print_work: bool = False):
    a = 1
    b = 1
    c = 2
    # loop 100 times
    for iteration in range(1, nth+1):
    c = a + b
    b = a
    a = c
    if print_work:
    print(a, b, c)
    if nth == 1:
    return 1
    elif nth == 2:
    return 1
    else:
    return c

  • @m.t-thoughts8919
    @m.t-thoughts8919 4 ปีที่แล้ว +57

    Beginners: "This was helpfully, thx."
    Pros: _"That's my daily ASMR, befor I go to bed"_

  • @royshemtov5526
    @royshemtov5526 2 ปีที่แล้ว

    This is actually the best version of the fibonacci sequence in python.
    No need for caching, no recursion problems just input any number n.
    and if you want a slice just slice through the resulted output to get any fibonacci number you want.
    def fib(n):
    a, b = 0, 1
    fib_arr = [ ]
    for _ in range(0, n):
    fib_arr.append(a)
    a, b = b, a + b
    return fib_arr

  • @reef2005
    @reef2005 4 ปีที่แล้ว

    Nothing illustrates the power of 'efficient programming' better than this Fibonacci sequence coding. Brilliant!

  • @prakashj3436
    @prakashj3436 3 ปีที่แล้ว

    def func(a):
    first=0
    second=1
    print(first)
    print(second)
    for i in range(1,a+1):
    third=first+second
    print(third)
    first,second=second,third
    func(101)
    This looks good!!!!

  • @trentsteele
    @trentsteele 3 ปีที่แล้ว

    wow, that emotionless, robotic delivery is the best. My brain loves this!

  • @yangalusiti3521
    @yangalusiti3521 5 ปีที่แล้ว

    Never under-estimate what you are doing for any second.... you are really changing lives and bringing hope to the humanity.

  • @alarmparvezanik5397
    @alarmparvezanik5397 3 ปีที่แล้ว

    the quality of tutorial of this channel is just on the upper level. please never stop making tutorial.

  • @MyAsdfqwe
    @MyAsdfqwe 8 ปีที่แล้ว +828

    I will not recommend this channel to anyone because i'm selfish.

    • @Socratica
      @Socratica  8 ปีที่แล้ว +156

      hehehehee nooooo! We need your help! :)

    • @xhhdbdhsb8192
      @xhhdbdhsb8192 8 ปีที่แล้ว +9

      He is Selfish

    • @xhhdbdhsb8192
      @xhhdbdhsb8192 8 ปีที่แล้ว +2

      Never Mind

    • @Lumenified
      @Lumenified 7 ปีที่แล้ว +3

      obscurantism !

    • @zbzb-ic1sr
      @zbzb-ic1sr 7 ปีที่แล้ว +13

      THIS CHANNEL IS GOLD

  • @eugenerider0701
    @eugenerider0701 5 ปีที่แล้ว +1

    WTF just happened, is this code magic????
    How did...
    What did...
    The def function didn't write anything, any equations, and it worked! It works as how we humans perceive fibonacci sequence.
    I mean... how???
    Everybody writes this down by doing value switching like
    a = b
    b = a + b
    c = a + b
    But this....
    It's so damn clean and so damn clarified. I am amazed by the high precision, almost like a robot, anchor lady's way of doing this algorithm.
    This is so cool.

    • @clock4883
      @clock4883 5 ปีที่แล้ว

      She did it way better. This was my very unproductive way:
      def fib(n):
      a, b = 0, 1
      while n > b:
      a, b = b, a+b
      return b

  • @DarkThoot
    @DarkThoot 8 ปีที่แล้ว +270

    She would match perfect the role of the humanized computer A.I. like Cortana from Halo. Thank you, I love your videos.

    • @RussellTeapot
      @RussellTeapot 7 ปีที่แล้ว +3

      ahahhaha I got some GladOS vibes watching the video (which, by the way, is spot on: concise but very informative)

    • @TheDavidlloydjones
      @TheDavidlloydjones 6 ปีที่แล้ว +1

      The word you're looking for is "self-satirical." But she is bright...

    • @sircharlitos
      @sircharlitos 5 ปีที่แล้ว

      Good ol' Cortana th-cam.com/video/JyL-J-piB8o/w-d-xo.html

    • @valkyriefrost5301
      @valkyriefrost5301 5 ปีที่แล้ว +1

      I suspect she's going for a more Vulcan from Star Trek vibe. Especially the way she is holding her hands together.

    • @liuqing1995
      @liuqing1995 5 ปีที่แล้ว

      Is she a real AI role?

  • @aviraljanveja5155
    @aviraljanveja5155 8 หลายเดือนก่อน +1

    The best explanation on the subject. A series on Python or DSA with same explanation format as above would kill it !

  • @mussaramadan
    @mussaramadan 6 ปีที่แล้ว

    One of the best teachers I ever seen she made it easy and simple....

  • @Juanj0se22
    @Juanj0se22 7 ปีที่แล้ว

    the fact that you didnt finished the tuto but when you added the param check, makes me believe that the quality of your videos are great :D keep it on!

  • @manideep6814
    @manideep6814 3 ปีที่แล้ว

    The wit and wisdom is next level in your videos !

  • @andrewfacchiano5117
    @andrewfacchiano5117 6 ปีที่แล้ว +3

    So...I've gone from "Ha! They are owning the hell out of this goofy sci-fi angle" Well on too "Oh wow... This is a million times better then the stale as hell tutorials I've seen online else where." You folks rock :)

  • @thedolphinboyo6866
    @thedolphinboyo6866 2 ปีที่แล้ว

    Daaaaaamn love the build up with the music at the end, didn't know I would get hyped for learning the golden ratio

  • @Socratica
    @Socratica  5 ปีที่แล้ว

    We're halfway there. We still need your help! Support Socratica Python Kickstarter: bit.ly/PythonKickstarter

  • @ABC-xn3td
    @ABC-xn3td 7 ปีที่แล้ว

    I hardly ever write comments on TH-cam. Mam, you are simply awesome. All your videos are fantastic. Thank you very much for imparting knowledge. God bless.

  • @ultratensao
    @ultratensao 7 ปีที่แล้ว

    This is the best channel in history of TH-cam video school. Thanks!

  • @jaimeduncan6167
    @jaimeduncan6167 2 หลายเดือนก่อน

    A little point, if you are doing the explicit version for some reason, compute the seed values before checking the cache. An integer comparison is much faster than a dictionary lookup. In reality programer time is more expensive than CPU time nowadays so better go with the decorator.

  • @MegaCkha
    @MegaCkha 7 ปีที่แล้ว +7

    This is the sophisticated learning. I am always waiting for. Love python. Love Socratica.

  •  4 ปีที่แล้ว

    I learn more from you in 8 minutes than from other videos in 2h!

  • @amarnathpolagangu
    @amarnathpolagangu 6 ปีที่แล้ว

    I have never seen this kind style of presentation. I am very much impressed.

  • @MrMichalXXL
    @MrMichalXXL ปีที่แล้ว

    I spent few hours trying to understand the problem (I understood how each line works but didn't understand how it works as a whole) but after watching this finally can grasp the idea and mechanism

  • @valanthonybalagon8468
    @valanthonybalagon8468 6 ปีที่แล้ว +1

    The tutorials are fast-paced but she explains very clearly.

  • @sathviks7442
    @sathviks7442 4 ปีที่แล้ว

    Does this mean we are done? That gave me shivers. Awesome.

  • @deepand9954
    @deepand9954 4 ปีที่แล้ว

    I love this way of explaining from india,chennai.
    Huge fan of your channel

  • @gopinathrajamanickam9475
    @gopinathrajamanickam9475 6 ปีที่แล้ว

    you are AWESOME ! . one small correction
    fib_cache = {}
    def fibbonacci(n):
    if n in fib_cache:
    return fib_cache[n]
    wont work it should be
    def fibbonacci(n):
    if n

  • @genesebarbosa
    @genesebarbosa 2 ปีที่แล้ว

    I’ve never thought to calculate Fibonacci series like this. Sure, I’ll watch this vide, over and over and over 😂😂, so I improve my knowledge and learn a little more about memoization. Thx 🇧🇷

  • @vietnguyen2354
    @vietnguyen2354 8 ปีที่แล้ว +134

    your voice is amazing!

    • @Socratica
      @Socratica  8 ปีที่แล้ว +37

      you are so kind, thank you! We're so glad you are enjoying our videos. :)

    • @RiteshNEVERUNIFORM
      @RiteshNEVERUNIFORM 4 ปีที่แล้ว +2

      @@Socratica the way you reply to comments makes me thing you are real AI

  • @birdeye700
    @birdeye700 5 ปีที่แล้ว

    This example shows the beauty of the caching method , simple and efficient ! Job well done!

  • @MrGustavCR
    @MrGustavCR 7 ปีที่แล้ว

    Love the video! I'm personally a fan of this similar, shorthand recursive syntax (probably less readable):
    fibonacci_dict = {0:0, 1:1}
    def fibonacci(n):
    if not n in fibonacci_dict:
    fibonacci_dict[n] = fibonacci(n-1) + fibonacci(n-2)
    return fibonacci_dict[n]

  • @chrs-wltrs
    @chrs-wltrs 4 ปีที่แล้ว

    The deadpan humor in these is fantastic.

  • @kennyPAGC
    @kennyPAGC 7 ปีที่แล้ว

    I understand the point of this video is showing how recursion works, but in practical terms we usually won't want to store a cache for EVERY single term in the fibonacci sequence. Therefore the best implementation in terms of performance is just using two variables like so:
    def fibonacci(n):
    x, y = 0, 1
    for _ in range(n):
    x, y = y, x + y
    return x

  • @MustbeTheBassest
    @MustbeTheBassest 3 ปีที่แล้ว

    The lru_cache decorator blew my mind!!

  • @wayde101
    @wayde101 4 ปีที่แล้ว

    She cracks me up, its the best place on the planet to lean to code, everybody should learn to code i do not care the language you choose but pi is delicious. thank you namaste.. to you and all

  • @vikrantchoudhary4411
    @vikrantchoudhary4411 2 ปีที่แล้ว

    the way you explain evrything is way better that coursera, thanks a lot.

  • @darcash1738
    @darcash1738 ปีที่แล้ว

    I did this problem a while back. I liked your solution but a 3 param approach is also pretty clean.
    def fib(3 params: cycles, n1=0, n2=1):
    if type(cycles) == int and cycles >= 1:
    if cycles == 1:
    prints n1 + n2
    else:
    prints n1+n2 (copied f string fr/if stmt)
    fib(cycles-1, n1=n2, n2=n1+n2)
    else:
    prints that it's a sad day indeed for Mr. Fibonacci

  • @manuxyz595
    @manuxyz595 3 ปีที่แล้ว

    Found your channel while looking for tuples, now going through your playlist. In love with your presentation.

    • @Socratica
      @Socratica  3 ปีที่แล้ว

      We're so happy you've found us! 💜🦉

  • @einstien2409
    @einstien2409 3 ปีที่แล้ว +1

    you sound like that lady in a horror game in the orientation video telling us not to panic if the world goes upside down.

  • @ChristopherKemsley
    @ChristopherKemsley 2 ปีที่แล้ว

    "People love to debate the smallest of details."
    At 5:38, you put @Lru_cache with a capital L, but imported the code with a lowercase L - which tells us the left frame isn't directly the editor being used to create the right frame.
    Really good video though! (Also I didn't know there was a built-in memoization tool)

  • @samiissam2113
    @samiissam2113 4 ปีที่แล้ว

    Before start watching any tutorial to learn about anything I check firstly how long time is this video then I decide to watch it or not because who can explain in few minutes give the most important things thanks a lot Socratica

  • @amaterasu48
    @amaterasu48 6 ปีที่แล้ว +8

    This video is great for learning recursion and lru_cache (which I didn't know) but fibonacci function doesn't have to be a recursive function. I love your videos so much that I'm going through all of them! :)
    def fib(n):
    a, b = 0, 1
    for i in range(n):
    a, b = b, a + b
    return a

  • @schlemmy
    @schlemmy 4 ปีที่แล้ว +1

    Strictly speaking I do not need recursion to compute values of the Fibonacci sequence. It is claimed at the beginning. Itbis even possible to compute them in a non-algorithmic way using linear algebra.

  • @meleksolaani3740
    @meleksolaani3740 4 ปีที่แล้ว

    I have never understood Memoization like that. THANK YOU!

  • @Hellangelx
    @Hellangelx 2 ปีที่แล้ว

    try this and no needed of memorization
    n = int(input())
    list = [1, 1]
    a, b = 1, 1
    while len(list) < n:
    a, b = b, a + b
    list.append(b)
    if you import time and check n = 100000 (video code range(1, 100001)
    you will see it is faster

  • @NaimaZakaria
    @NaimaZakaria 8 ปีที่แล้ว +26

    delivery is seriously legend! love 😍

  • @mullergyula4174
    @mullergyula4174 7 ปีที่แล้ว

    I did not want to learn python, but now I'm tempted. ;)

  • @bevster1
    @bevster1 ปีที่แล้ว

    Excellent video. Lots of concepts explained very clearly and concisely. It will be very helpful for my Computer Science students. Thanks a lot!

  • @anthonyowens30
    @anthonyowens30 7 ปีที่แล้ว

    These videos are just the right length for learning on the go!

  • @bakarydiallo895
    @bakarydiallo895 2 ปีที่แล้ว

    the voice that makes you intelligent.
    gonna watch all :)

  • @MrOmniblast
    @MrOmniblast 7 ปีที่แล้ว +42

    This channel is criminally undersubbed and underrated. I don't even understand! Sexism? Bad marketing? I do not understand! lol

    • @Socratica
      @Socratica  7 ปีที่แล้ว +35

      We're definitely growing more slowly than we'd like, but we're sticking with it! Our marketing budget is currently $0. :) We currently grow by word of mouth. It's amazing how much of an impact sharing our videos can have. Once someone shared a single one of our Abstract Algebra videos on a discussion board, and it was the biggest day we ever had.

    • @FullMetal-nu8bj
      @FullMetal-nu8bj 7 ปีที่แล้ว +13

      Why do people like you make everything a gender issue?

    • @monkey5266
      @monkey5266 7 ปีที่แล้ว +6

      hes not making it about gender, I think what he is saying is people might not watch them because its a women speaking

    • @FullMetal-nu8bj
      @FullMetal-nu8bj 7 ปีที่แล้ว +7

      You have just proven my point. If it weren't a gender issue, the speaker being a women would be immaterial.

    • @iLoveTurtlesHaha
      @iLoveTurtlesHaha 7 ปีที่แล้ว +1

      I'm sure if they continue to do tech videos, some day this channel will get huge. Also, as they do collaborations with other popular channels they get mini boosts too. Maybe they should consider contacting CrashCourse and doing something together. But yeah, I hope they never stop doing tech videos and perhaps increase this type of content in their channel.

  • @denizasr
    @denizasr 3 ปีที่แล้ว

    I'm so glad I found your channel

  • @michalms7218
    @michalms7218 4 ปีที่แล้ว

    look nice, amazing voice :-)
    very good example for Recursion which also allow to easy check the limit:
    when
    n=1M
    => RecursionError: maximum recursion depth exceeded in comparison
    in simple naive function it still works:
    def fib(n):
    a, b = 0,1
    f = 0
    for i in range(2,n+1):
    f = a + b
    a = b
    b = f
    return f
    fib(1000000) => time 7,4 s
    (naive so to long anyway, but still works)
    once again thank you very much it was nice video it was a pleasure to listen
    All the best :-)

  • @jursamaj
    @jursamaj ปีที่แล้ว

    A quibble: you don't *have* to use recursion. Anything that can be computed recursively, can also be computed iteratively. Doing so is much faster, as it avoids the exponential explosion of the recursive method.

  • @mcan543
    @mcan543 4 ปีที่แล้ว +1

    #KeyTakeAways
    4:56 Explicit caching
    5:21 functools.lru_cache
    6:26 Don't skip type checking

  • @mrwasteoffood
    @mrwasteoffood 7 ปีที่แล้ว

    Best coding teacher

  • @PunmasterSTP
    @PunmasterSTP 3 ปีที่แล้ว

    Another phenomenal video from Socratica! I watched until the very end, and now I'm golden!

  • @DanielMartinez-yv9gp
    @DanielMartinez-yv9gp 4 ปีที่แล้ว

    In recent versions of python (I believe >2.7, not sure though) the call to the decorator has to be in lower case:
    @Lru_cache(...) -> @lru_cache(...).
    In the video the 'L' looks uppercase and I had to figure out why my code couldn't find the decorator.
    Good videos btw !!. Short and simple, easy to take notes on what I didn't know.

  • @natenate2280
    @natenate2280 7 ปีที่แล้ว

    earned a new sub, and I say earned because saying gained wouldn't do this channel justice

  • @darshika9124
    @darshika9124 4 ปีที่แล้ว +1

    It's really amazing. The way you taught it made me a big fan of yours.

  • @dcarty
    @dcarty 7 ปีที่แล้ว

    This made recursion so easy to understand.

  • @OverLordOfDa3rdWorld
    @OverLordOfDa3rdWorld 5 ปีที่แล้ว

    THIS IS INSAAAANE, MEMOIZATION IS CRAAAAZYYYYYYYYY!!!
    I love it !

  • @harrybarrow6222
    @harrybarrow6222 4 ปีที่แล้ว

    I love Socratica videos. I love the AI persona. 😍

  • @boyananakiev4896
    @boyananakiev4896 7 ปีที่แล้ว

    I must admit I originally did not click your videos due to your thumbnails. The youtube algorithm must be working in your favour since many of them were suggested to me (since I'm learning python), however I never clicked until recently due to the fact that I thought it's not a real channel and it's simply using click bait images with women/girls while discussing a programming language...
    I'm not sure if I'm the one here to fault for associating this wrongly or if just repetitive miss use of thumbnails on youtube have trained people to do it but in any case I'm glad I clicked and I'm very surprised that your channel has only 115k subs. I've looked through your playlists and watched a couple of videos from each one and they're all great.
    In particular, I really appreciate the style that is added for the programming with python. You begin with some kind of reference/riddle/statement and you end with it making a good association (and a funny one) back to your channel which I think really gives uniqueness to the videos. As well as the chipset dress (uniform) and the general editing of the videos, it really adds an extra thing which you rarely see in other tutorials (no matter how great they are)
    Looking back to it as well, I think the thumbnails are absolutely fine and definitely propagate the brand of the channel and make it more recognisable (as soon as you're familiar with it).
    Can't wait for more python. I finally sort of understand recurring functions, though It's still too early for me to think of good uses of them. One thing I'm struggling now with python is that I'm learning a lot on how the language works.. I understand the basics such as classes/functions/comprehensions/sets/data types/objects etc. but I'm not too sure how to practise this as if I don't I'll simply forget it do you happen to have a recommendations of some recourses to practise python ?

  • @yogabija
    @yogabija 4 ปีที่แล้ว

    I like the style of the video. In the video you say you have to use recursion for fibonachi. Thats not true, but I suspect that you wanted to show some of the language features, which was interesting and useful.
    Python
    =========
    max=2000
    x = 1
    y = 1
    z = 0
    count = 0
    while count < max:
    count = count + 1
    print('' + str(count) + ' ' + str (x) )
    z = x
    x = y
    y = x + z
    JavaScript
    ===========
    var max=100;
    for (x=1,y=1,z=0,count=1;count

  • @nanotips_
    @nanotips_ 3 ปีที่แล้ว

    @lru_cache(maxsize=someint) is written with a lowercase "l", for future reference... Very good video!

  • @anterprites
    @anterprites ปีที่แล้ว

    2:22 That's why I usually write range(1, 10+1) as a reminder

  • @thehanke
    @thehanke 4 ปีที่แล้ว +1

    This is so beautifully explained that I can feel my brain tingling..

  • @uboxer
    @uboxer 7 ปีที่แล้ว +1

    Unique presentations by a unique teacher.. just WOW !

  • @devendratapdia11
    @devendratapdia11 7 ปีที่แล้ว +2

    This was amazing. Not just presentation but the content

  • @royz_1
    @royz_1 5 ปีที่แล้ว

    "maxsize" argument doesn't have to be 1000. It can be set to 3 in case of fibonacci function. Because there's no need to cache all "least recently used " values. We just need last 3 values (I initially thought we need 2 values only, but maxsize=3 gives the desired result. Not sure why)

  • @5thfloor584
    @5thfloor584 2 ปีที่แล้ว

    Is this some AI ? Needed to use python recursion for a uni assignment, now this holy AI is helping me.

  • @Sherazkhan-py6pr
    @Sherazkhan-py6pr 4 ปีที่แล้ว

    Thank you so much! I was stuck in memoization, but this tutorial removed all my doubts.

  • @NaimaZakaria
    @NaimaZakaria 8 ปีที่แล้ว +6

    I have no 💡 why that felt so funny to listen to. Impeccable deliveryB-)

  • @CentboyMidnight
    @CentboyMidnight 6 ปีที่แล้ว +6

    I got follow this tutorial but with some difficulties, I just started to learn python 2 weeks ago in a self-taught way and today I find out your channel, and I have to say, the quality of your work is just stunning, inmediately I subscribed.
    May you suggest me a good point to start with your channel taking in count my level?
    By the way, I have some experiece in c#, so for that I was able to follow this video but was a bit overwhelming / exhausting

  • @andrewbarzu6617
    @andrewbarzu6617 4 ปีที่แล้ว +1

    There is one more method: rather than doing it in a recursive function just do it iteratively. It's a lot faster and takes no memory. If you need memoization for the future you can use a list rather than a dict, which for sure will have no collisions and won't have to compute hashes.

  • @Waitwhat469
    @Waitwhat469 5 ปีที่แล้ว

    Love these videos, despite using python all the time, I learn something new every video just awesome.
    One optimization I would recommend though is for handling type errors would be to use a try catch exception block.
    So instead of:
    if type(n) != int:
    raise ...
    if n > 1:
    raise ...
    you instead could do :
    @lru_cache(maxsize = 1000)
    def fib(n):
    try:
    if n == 1:
    return 1
    elif n == 2:
    return 1
    elif n > 2:
    return fib(n-1) + fib(n-2)
    #This is added because negative numbers do not thrown an exception naturally
    elif n < 1:
    raise ValueError("n must be a positive int")
    #This catches all other shown cases
    except (TypeError):
    raise TypeError("n must be a positive int")
    This will instead allow the code to run without checking the data before hand. So successful calls do not have an added check. It is only if it fails to meet the previous if statements or throws an TypeError exception.

  • @imadetheuniverse4fun
    @imadetheuniverse4fun 3 ปีที่แล้ว

    Oooh this is cool! here's my take on a more concise but less readable method:
    def fibonacci(n):
    return fibonacci(n - 1) + fibonacci(n - 2) if n > 2 else 1
    I don't think it's *too* unreadable?

  • @opeoluwa845
    @opeoluwa845 6 ปีที่แล้ว

    this is the right place to learn programming

  • @ar_x7
    @ar_x7 7 ปีที่แล้ว

    Recursion are so cool if you get it and see when its needed. It makes your code look clean. I personally have a hard time understanding it sometimes, like making the knights tour function.

  • @CJRH1FILMS
    @CJRH1FILMS 4 ปีที่แล้ว

    I definitely need more of this. Like, way more.