What Are Differences Between type() and isinstance()?

The main difference between type() and isinstance() is that type(object) returns the type of an object and isinstance(object, class) returns True if the object argument is an instance of the class argument or in a direct or indirect subclass relationship. To strengthen your understanding, let’s quickly recap the syntactical definitions of both functions: type(object) – … Read more

SVM sklearn: Python Support Vector Machines Made Simple

Support Vector Machines (SVM) have gained huge popularity in recent years. The reason is their robust classification performance – even in high-dimensional spaces: SVMs even work if there are more dimensions (features) than data items. This is unusual for classification algorithms because of the curse of dimensionality – with increasing dimensionality, data becomes extremely sparse … Read more

How to Fill a Python String with Spaces?

Problem Formulation Given a Python string s with length k<=n. How to fill the string with n-k empty spaces on the left so that the new string has length n? Here are some examples: INPUT: ‘a’, n = 2 OUTPUT: ‘a ‘ INPUT: ‘hi’, n = 4 OUTPUT: ‘hi ‘ INPUT: ‘hi’, n = 2 … Read more

How to Kill a While Loop with a Keystroke in Python?

To end a while loop prematurely in Python, press CTRL-C while your program is stuck in the loop. This will raise a KeyboardInterrupt error that terminates the whole program. To avoid termination, enclose the while loop in a try/except block and catch the KeyboardInterrupt. You can see the idea in the following code snippet: The … Read more

[Google Interview] The Gas Station Problem

?️ Company Tags: Google, Facebook, Amazon Are you gearing up for your coding interview? If your answer is yes, then here’s a very interesting interview question for you. Numerous programmers have claimed that they came across this interview question. Hence, there is a high probability that you might come across it as well in your interview. Will you be able … Read more

Python Scikit-Learn Decision Tree [Video + Blog]

Decision Trees are powerful and intuitive tools in your machine learning toolbelt. Decision trees are human-readable – in contrast to most other machine learning techniques. You can easily train a decision tree and show it to your supervisors who do not need to know anything about machine learning in order to understand how your model … Read more