Santiago Profile picture
Feb 8 11 tweets 2 min read
If you look at this code and think the answer is False, you aren't alone.

Nevertheless, we are all wrong: it returns True.

Read on to see what's happening.

The clue here is the two consecutive operators next to each other.

Operator 1: ==
Operator 2: in

And we have "False" sandwiched in the middle.

The logical reaction is to parse the statement piece by piece. That's what I did.

But that's not how it works.
When it comes to answering this question, there are two camps:

1. Those who claim that "==" takes precedence.

2. Those who claim that "in" takes precedence.

Let's see what we get on both of these cases.
Assuming that "==" takes precedence:

• False == False is True
• True in [False] is False

People on this camp claimed the answer was False.
Assuming that "in" takes precedence:

• False in [False] is True
• False == True is False

People on this camp also claimed the answer was False.
The problem is that this has nothing to do with operator precedence.

Instead, this statement translates to the following:
This is called "Chained Operators" in Python.

A similar (and probably more intuitive example) is attached.

It translates to 10 < x and x < 20.
After understanding how you "unroll" chained operators, it becomes evident that the answer is True.

There's a lesson here.
Regardless of how cool you think chained operators are, I find them confusing.

Judging by the attached post, most people feel the same.

This is a good indication that you should stay away from them as much as possible.

I'm usually in favor of mastering your language and using as much of it as you possibly can.

That being said, there's a difference between using something that people don't understand and something that people misunderstand.

The latter is very problematic.
So, although a fun exercise, I prefer to stay away from chained operators.

What do you think?

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Santiago

Santiago Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @svpino

Feb 6
Guess the output and don't cheat.

(This is Python) Image
If you pay careful attention you will realize the equal sign seems strangely elongated.

The reason is because it’s not an equal sign but an ==.

A font ligature causes this effect.

So, no assignment. It’s an equality.
If you are surprised about the answer here, look into “chained comparison” in Python so you can see how it works.
Read 4 tweets
Jan 29
When I started with machine learning, I always made the same mistake:

I confused a couple of metrics that look very similar but are entirely different.

Let's fix that for you.

2. When we train a machine learning model, we need to compute how different our predictions are from the expected results.

For example, if we predict a house's price as $150,000, but the correct answer is $200,000, our "error" is $50,000.
3. There are multiple ways we can compute this error, but two common choices are:

• RMSE — Root Mean Squared Error
• MAE — Mean Absolute Error

These have different properties that will shine depending on the problem you want to solve.
Read 15 tweets
Jan 28
Can you guess what their biggest struggle is?

I regularly talk to companies using machine learning, from Fortune-500 to the ice cream parlor in the block around the corner.

Surprisingly, building models is not an issue for them.

Wanna guess? ↓
"Don't worry about the model" is what I usually get.

The real struggle? → "What do we do with this Jupyter notebook running the model that we built"?

It's not about building models. It's about making them useful.
Many feel like having a model is the end of the road.

In reality, it is just the beginning.

The fundamental hurdle is understanding what to do with them.
Read 8 tweets
Jan 24
I built a machine learning model that predicts whether your car will crash today.

And it's 99% accurate!

Here is the secret: ↓
This thread is the answer to this question.
Before getting into the details, let's jump right into the source code of my model:
Read 10 tweets
Jan 21
Occam's Razor:

Given two solutions with similar characteristics, the simplest and most direct one is the correct answer.

This thread answers the following question:
Option 3 is probably the simplest one to tackle first.

It talks about "the speed of the training process" and relates it to overtraining and overcomplicating results.

A quick training process doesn't necessarily reduce complexity. This option is not correct.
Read 7 tweets
Jan 21
Three deep learning myths:

1. A lot of math is needed
2. A lot of data is needed
3. An expensive computer is needed

If these are preventing you from starting, reconsider.

(Hat tip to the FastAI Course.)
Data Structures and Algorithms are an underrated set of skills for any software professional.

They are definitely very important!

That being said, I don't think they are absolute requirements for deep learning work.

Understanding the math underpinnings of anything you do will definitely open doors for you.

However, stating that you can't do deep learning unless you understand all of the math involved is not a serious statement.

Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

:(