Happy Thanksgiving to my role model @lexfridman, my dear friend @sandrag926, and others on X who celebrate this holiday 🥘🍲🍂
Lex is traveling, so this year he won’t get to have a cozy feast with his family? I hope he shares his location with his mom regularly so she won’t worry too much.
1
1
46
In this sample code (attached pic, or at 43:20 of the YouTube lecture, link below), the lecturer was using super() in the implementation of RunWorkout to invoke the __init__ method of Workout and said that super() returned Workout - the parent class itself. This is incorrect. In fact, super() returns a proxy object (a super object), not the parent class of the class being defined.
In more detail, super() is built-in function that returns a proxy object allowing you to access methods from the next class in the Method Resolution Order (MRO). This is a very important point. Using super() doesn't simply mean "call my parent class", it means: call the next class in the MRO.
So what is MRO? Every class has its own MRO, determined by its inheritance hierarchy. When Python creates a class, it also calculates the class's MRO. This will be the order in which Python searches classes for a method or attribute when dealing with inheritance, especially multiple inheritance (a subclass having two or more parent classes). MRO tells Python: "If I call a method on an object of this class, which class should I look in first, second, third, and so on?"
super() follows the MRO of the class of the object/instance on which the method is called. Let's illustrate this with an example:
class A:
def speak(self):
print("A speaks.")
class B(A):
def speak(self):
print("B speaks.")
super().speak()
class C(A):
def speak(self):
print("C speaks.")
super().speak()
class D(B, C):
pass
d = D()
d.speak()
Output of the code is:
B speaks.
C speaks.
A speaks.
Why? First, let's examine the MRO of D:
print(D.mro()) # [D, B, C, A, object]
Here's what happens:
1. D doesn't define speak(), so Python finds it in B.
2. B.speak() executes. Its super() continues to C because C is the next class in D's MRO.
3. C.speak() executes. Its super() continues to A.
4. A.speak() executes.
------
Link to the YouTube lecture: youtube.com/watch?v=-wyc5Fwz…
76
I think @lexfridman might be interested in reading Mr. Ngo Bao Chau's perspective on the Riemann hypothesis being solved with the help of AI. He's a renowned Vietnamese mathematician and a 2010 Fields Medalist. Our pride 💖
1
115
Now that @lexfridman is out enjoying the great outdoors and commenting on girls’ posts, he should also update his status sometimes so that his fans feel reassured about his situation.
1
93
Dictionaries are useful for counting word frequencies, which is a common programming exercise. However, we can also use the get() method to shorten the code, rather than checking whether each word in the string already exists in the dictionary we're building.
Notice how count_words1() performs fewer operations than count_words() while producing the same result.
get(key, default=None) returns the value associated with a key. If the key doesn't exist, it returns the default value instead of raising a KeyError. Compare this with direct indexing: student["grade"] raises a KeyError if the key 'grade' doesn't exist in the dictionary 'student'. This is one of the main advantages of get()
1
70
I love seeing pictures of Crown Prince Mohammed bin Salman in his office. He's such a hardworking and responsible leader 🥰
Some people even managed to identify the bottle of perfume on his desk. You can also see a bit of the bottle in the second photo of the post I retweeted.
The Crown Prince is indeed a man of class and refined taste. I'm sure the fragrance of His Handsome Highness is irresistible, with or without his favourite perfume 🥺
Thanks to the reform initiatives spearheaded by Crown Prince Mohammed bin Salman, more Saudi women are joining the workforce and contributing to the development of their country. Saudi female students are also achieving remarkable academic success.
I'm Vietnamese, yet I feel proud of these achievements because I admire the Crown Prince's vision and his accomplishments in transforming his country 🥰
@KingSalman @HRHMBNSALMAAN @KSAmofaEN @spagov @Spa_Eng @Badermasaker @Bandaralgaloud @TheMoShowPod @r___66e @ksaembassyvn
Joudi Al-Ahmadi and Lena Al-Shanafey have won the prestigious Rhodes Scholarships for Saudi Arabia this year arab.news/nuxgf
1
2
426
I need to issue a correction for this tweet. In the first sentence, I meant function gcd(), not function reduce()
I was learning this piece of code and encountered the Euclidean algorithm, which is used to find the greatest common divisor (GCD) of two integers without having to list all their factors (function reduce() in the code). Learning to code allows me to brush up on my math knowledge as well 🥰
The key mathematical principle behind the Euclidean algorithm is: gcd(a, b) = gcd(b, a mod b). In other words, the GCD of two integers is equal to the GCD of the smaller integer and the remainder when the larger integer is divided by the smaller one. You repeat this process until the remainder becomes zero. The last nonzero remainder is the GCD.
Let's prove this algorithm. Suppose: a > b and a = bq + r where q is the quotient and r is the remainder. Any integer that divides both a and b must also divide r, because r = a - bq.
=> Every common divisor of a and b is also a common divisor of b and r (1)
Conversely, any integer that divides both b and r must also divide a, because a = bq + r
=> Every common divisor of b and r is also a common divisor of a and b (2)
From (1) and (2), we see that the two pairs (a, b) and (b, r) have exactly the same set of common divisors. Consequently, their greatest common divisors must be equal: gcd(a, b) = gcd(b, r)
We can also prove that the last nonzero remainder gives the GCD. Start with two positive integers a > b and apply the property gcd(a, b) = gcd(b, r) repeatedly:
a = bq₁ + r₁
b = r₁q₂ + r₂
r₁ = r₂q₃ + r₃
...
rₙ₋₂ = rₙ₋₁qₙ + rₙ
rₙ₋₁ = rₙqₙ₊₁ + 0
We have: gcd(a, b) = gcd(b, r₁) = gcd(r₁, r₂) = ... = gcd(rₙ₋₁, rₙ). The final division tells us that rₙ divides rₙ₋₁. Therefore, gcd(rₙ₋₁, rₙ) = rₙ. Hence, gcd(a, b) = rₙ
1
250
I wish @lexfridman would share pictures from his motorcycle journey with us from time to time. We have no idea where he is right now or whether he's traveling alone. And I hope his loved ones are able to keep track of his whereabouts. @gregfridman
1
213
I was learning this piece of code and encountered the Euclidean algorithm, which is used to find the greatest common divisor (GCD) of two integers without having to list all their factors (function reduce() in the code). Learning to code allows me to brush up on my math knowledge as well 🥰
The key mathematical principle behind the Euclidean algorithm is: gcd(a, b) = gcd(b, a mod b). In other words, the GCD of two integers is equal to the GCD of the smaller integer and the remainder when the larger integer is divided by the smaller one. You repeat this process until the remainder becomes zero. The last nonzero remainder is the GCD.
Let's prove this algorithm. Suppose: a > b and a = bq + r where q is the quotient and r is the remainder. Any integer that divides both a and b must also divide r, because r = a - bq.
=> Every common divisor of a and b is also a common divisor of b and r (1)
Conversely, any integer that divides both b and r must also divide a, because a = bq + r
=> Every common divisor of b and r is also a common divisor of a and b (2)
From (1) and (2), we see that the two pairs (a, b) and (b, r) have exactly the same set of common divisors. Consequently, their greatest common divisors must be equal: gcd(a, b) = gcd(b, r)
We can also prove that the last nonzero remainder gives the GCD. Start with two positive integers a > b and apply the property gcd(a, b) = gcd(b, r) repeatedly:
a = bq₁ + r₁
b = r₁q₂ + r₂
r₁ = r₂q₃ + r₃
...
rₙ₋₂ = rₙ₋₁qₙ + rₙ
rₙ₋₁ = rₙqₙ₊₁ + 0
We have: gcd(a, b) = gcd(b, r₁) = gcd(r₁, r₂) = ... = gcd(rₙ₋₁, rₙ). The final division tells us that rₙ divides rₙ₋₁. Therefore, gcd(rₙ₋₁, rₙ) = rₙ. Hence, gcd(a, b) = rₙ
Btw my role model @lexfridman you can fall in love and have babies, but please don’t get married 😠 Haven’t you learned anything from the Jensen case at all?? I’m not going to get married to any man whatsoever, even to the Crown Prince of Saudi Arabia who is absolutely adorable as well. What if I become a billionaire in the future, who knows, or I become infatuated with another man? I need to have the option of walking away without losing my large fortune 😠
1
159
But this is a very long loooong journey 🥹 Maybe @lexfridman should take frequent breaks and make time to get to know his fans in Asia, who have always supported him wholeheartedly. I'm his biggest fan in Vietnam, how come I haven't had the chance to see my role model in person?
1
126
Please stay safe on the road @lexfridman 🙏🙏🍀
Your fans have been missing you but you don’t know about that 😔
1
120
A leader who is willing to help those who are just starting out in their careers is truly admirable ❤️
This quoted post is unavailable.
1
150
Onto the next great thing 🍀
Forget and keep moving 💪
@JensenHuang @lexfridman
Months before the scandal, Jensen Huang explained exactly how he deals with embarrassment
The Nvidia CEO admitted he hits low points “all the time”, and his answer is to forget and keep moving
“A lot of it is you gotta be tough on yourself. Come on, stop crying about it. Let’s get going”
“The embarrassments are gonna surprise you, the humiliations are gonna surprise you”
“Forget about it, move on, keep moving”
2
253
Crown Prince Mohammed bin Salman appeared cheerful and in good spirits yesterday as he went about his usual duties as Saudi Arabia's leader, even though we all know that the conflict involving the Houthis is still ongoing.
I've always had the impression that the Crown Prince is an optimistic and cheerful person. His smile is genuine and contagious, and it has been a constant source of joy and comfort to many Saudis, his fans around the world, and indeed anyone who follows Middle Eastern politics.
I believe that with this positive attitude, Crown Prince MBS will find ways to overcome the current Houthi threat. There's a solution to every problem, and inshallah, a sustainable solution to this one will emerge soon.
The second picture shows some lovely words I found on a chocolate bar I bought in the Netherlands back in September. (I've recently cut out sweets as part of my efforts to improve my health and appearance.) I kept the wrapper as a souvenir because of these beautiful words: "I achieve my goals with joy and laughter."
I think that's just the right attitude to have when facing any challenge, and it's also something I've learned from following Crown Prince MBS. I wish him and the people of Saudi Arabia all the very best ❤️
@KingSalman @HRHMBNSALMAAN @KSAmofaEN @Badermasaker @Bandaralgaloud @FaisalbinFarhan @kbsalsaud @arabnews @spagov @Spa_Eng @TheMoShowPod @r___66e @ksaembassyvn
Looking at photos of King Salman in his youth, it's easy to see how much Crown Prince Mohammed bin Salman resembles his father.
Even when I showed my best friend this picture of Saudi Arabia's past and present leaders, she immediately recognized the first two as father and son. 🥰
27
2,145


























