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!! 💜🦉
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!
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.
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?
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!
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
Welcome to Socratica! You can see our entire Python Playlist here: bit.ly/PythonSocratica Subscribe to see all our new videos! bit.ly/SocraticaSubscribe
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
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
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!!!!
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.
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!
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 :)
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.
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.
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
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
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 🇧🇷
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]
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
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
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
"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)
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
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
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.
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
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.
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.
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 :-)
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.
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.
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 ?
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
"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)
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
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.
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.
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?
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.
Wear a Socratica Python shirt for good luck coding: shop.socratica.com/products/python-by-socratica
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!! 💜🦉
i am waiting for your videos
Can you make a video on oop in Python pls ???
@@longLivejay1 Yes! I too want OOP Python!
can u plz make video more on algo
"People love to debate the smallest of details." Understatement of the 21st century!
I love Socratica's voice, honestly, she does have a clear, direct, cogent voice and excellent pronunciation. I truly love and enjoy your videos.
You are so kind, thank you! We're so happy you're watching!! 💜🦉
I laughed so hard when she said "Frustrating... I know" with her kind of robotic tone XDDDDD
Hi
From where u are
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!
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.
wow me too learning Python again after 5 years of break.
That deadpan delivery makes this learning experience the best I've ever had.
i dig the dry humor
sooo true
Did you create the lambda function ahhahahahhahha
I know I love her! I'm addicted
Support what you love! Socratica has a Kickstarter to make more Python: bit.ly/PythonKickstarter
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?
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!
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
Optimization is beautiful. The difference of speed between the before and after is insane.
Way of teaching is unique and effective. Thank you....
Netflix : meh
Socratica : all day every day!!!! ❤️
Thank you very much for the tutorials
Welcome to Socratica! You can see our entire Python Playlist here: bit.ly/PythonSocratica
Subscribe to see all our new videos! bit.ly/SocraticaSubscribe
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
The issue with recursion is, that you must understand recursion before you can understand recursion.
that little humor...robot-like accent...amazing background sound effects...this is unbeatable
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
Beginners: "This was helpfully, thx."
Pros: _"That's my daily ASMR, befor I go to bed"_
Helerious Hhhhhhhh
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
Nothing illustrates the power of 'efficient programming' better than this Fibonacci sequence coding. Brilliant!
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!!!!
wow, that emotionless, robotic delivery is the best. My brain loves this!
Never under-estimate what you are doing for any second.... you are really changing lives and bringing hope to the humanity.
the quality of tutorial of this channel is just on the upper level. please never stop making tutorial.
I will not recommend this channel to anyone because i'm selfish.
hehehehee nooooo! We need your help! :)
He is Selfish
Never Mind
obscurantism !
THIS CHANNEL IS GOLD
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.
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
She would match perfect the role of the humanized computer A.I. like Cortana from Halo. Thank you, I love your videos.
ahahhaha I got some GladOS vibes watching the video (which, by the way, is spot on: concise but very informative)
The word you're looking for is "self-satirical." But she is bright...
Good ol' Cortana th-cam.com/video/JyL-J-piB8o/w-d-xo.html
I suspect she's going for a more Vulcan from Star Trek vibe. Especially the way she is holding her hands together.
Is she a real AI role?
The best explanation on the subject. A series on Python or DSA with same explanation format as above would kill it !
One of the best teachers I ever seen she made it easy and simple....
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!
The wit and wisdom is next level in your videos !
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 :)
Daaaaaamn love the build up with the music at the end, didn't know I would get hyped for learning the golden ratio
We're halfway there. We still need your help! Support Socratica Python Kickstarter: bit.ly/PythonKickstarter
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.
This is the best channel in history of TH-cam video school. Thanks!
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.
This is the sophisticated learning. I am always waiting for. Love python. Love Socratica.
I learn more from you in 8 minutes than from other videos in 2h!
I have never seen this kind style of presentation. I am very much impressed.
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
The tutorials are fast-paced but she explains very clearly.
Does this mean we are done? That gave me shivers. Awesome.
I love this way of explaining from india,chennai.
Huge fan of your channel
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
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 🇧🇷
your voice is amazing!
you are so kind, thank you! We're so glad you are enjoying our videos. :)
@@Socratica the way you reply to comments makes me thing you are real AI
This example shows the beauty of the caching method , simple and efficient ! Job well done!
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]
The deadpan humor in these is fantastic.
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
The lru_cache decorator blew my mind!!
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
the way you explain evrything is way better that coursera, thanks a lot.
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
Found your channel while looking for tuples, now going through your playlist. In love with your presentation.
We're so happy you've found us! 💜🦉
you sound like that lady in a horror game in the orientation video telling us not to panic if the world goes upside down.
"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)
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
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
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.
I have never understood Memoization like that. THANK YOU!
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
delivery is seriously legend! love 😍
I did not want to learn python, but now I'm tempted. ;)
Excellent video. Lots of concepts explained very clearly and concisely. It will be very helpful for my Computer Science students. Thanks a lot!
These videos are just the right length for learning on the go!
the voice that makes you intelligent.
gonna watch all :)
This channel is criminally undersubbed and underrated. I don't even understand! Sexism? Bad marketing? I do not understand! lol
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.
Why do people like you make everything a gender issue?
hes not making it about gender, I think what he is saying is people might not watch them because its a women speaking
You have just proven my point. If it weren't a gender issue, the speaker being a women would be immaterial.
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.
I'm so glad I found your channel
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 :-)
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.
#KeyTakeAways
4:56 Explicit caching
5:21 functools.lru_cache
6:26 Don't skip type checking
Best coding teacher
Another phenomenal video from Socratica! I watched until the very end, and now I'm golden!
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.
earned a new sub, and I say earned because saying gained wouldn't do this channel justice
It's really amazing. The way you taught it made me a big fan of yours.
This made recursion so easy to understand.
THIS IS INSAAAANE, MEMOIZATION IS CRAAAAZYYYYYYYYY!!!
I love it !
I love Socratica videos. I love the AI persona. 😍
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 ?
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
@lru_cache(maxsize=someint) is written with a lowercase "l", for future reference... Very good video!
2:22 That's why I usually write range(1, 10+1) as a reminder
This is so beautifully explained that I can feel my brain tingling..
Unique presentations by a unique teacher.. just WOW !
This was amazing. Not just presentation but the content
"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)
Is this some AI ? Needed to use python recursion for a uni assignment, now this holy AI is helping me.
Thank you so much! I was stuck in memoization, but this tutorial removed all my doubts.
I have no 💡 why that felt so funny to listen to. Impeccable deliveryB-)
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
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.
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.
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?
this is the right place to learn programming
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.
I definitely need more of this. Like, way more.