DEV Community

Cover image for Don't Treat One Like Another
Naufan Rusyda Faikar
Naufan Rusyda Faikar

Posted on • Updated on

Don't Treat One Like Another

One day, someone has asked on Discord:

>>> import numpy as np
>>> my_list = [[1,2], [2,3], [3,4], [4,5]]
>>> [1,3] in my_list
False
>>> my_array = np.array(my_list)
>>> [1,3] in my_array
True
Enter fullscreen mode Exit fullscreen mode

Why numpy is doing so?

They are not the same as we already know. So, why do we expect them to behave the same? Every programming language, library, and whatsoever has its own implementation. True, it is all about different implementations, after all. We can even have this weirdo:

>>> a = 1
>>> b = 1
>>> a == b
True
>>> a is b
True
>>> a = 9999
>>> b = 9999
>>> a == b
True
>>> a is b
False
Enter fullscreen mode Exit fullscreen mode

See? So, it is not ever a good idea to treat anybody the same way, for you and I are unique~ Although, in some ways, we are still comparable.

By the way, if you are curious of the two, you can follow up by reading:

Take care!

Top comments (0)