Python __lshift__() Magic Method

Syntax object.__lshift__(self, other) The Python __lshift__() method implements the built-in << operation. So, when you cal x << y, Python attempts to call x.__lshift__(y). If the method is not implemented, Python first attempts to call __rlshift__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this a “Dunder … Read more

Self-Employed Programmer? A Simple Heuristic

Python Freelancer

Should you become your own boss, being self-employed? This is a valid question given the massive opportunities these days. Freelancing is growing double-digits percentages every year: One of the largest freelancing platforms Fiverr recently reported an 89% (!) annual growth rate! ? This article and video will help you decide if this opportunity is for you! … Read more

Python __pow__() Magic Method

Syntax object.__pow__(self, other) The Python __pow__() method implements the built-in exponentiation operation. So, when you call pow(a, b) or a ** b, Python attempts to call x.__pow__(y). If the method is not implemented, Python first attempts to call __rpow__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call … Read more

Python Namespaces Made Simple

Namespace are everywhere in Python whether you realize it or not. If you don’t know about Python namespaces, you’ll eventually introduce nasty bugs into your Python code. Let’s fix this once and for all! 🙂 As you read over the article, you can watch my explainer video: Why Namespaces? In many classes with 30+ students, … Read more

[Google Interview] Detect Capital

[toc] Company Tag: Google Problem Formulation We define the usage of capitals in a word to be right when one of the following cases holds: Rule 1: All letters in this word are capitals, like “USA”. Rule 2: All letters in this word are not capitals, like “welcome”. Rule 3: Only the first letter in … Read more

Python __divmod__() Magic Method

Syntax object.__divmod__(self, other) The Python __divmod__() method implements the built-in divmod operation. So, when you call divmod(a, b), Python attempts to call x.__divmod__(y). If the method is not implemented, Python first attempts to call __rdivmod__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this a “Dunder Method” … Read more

Python __mod__() Magic Method

Syntax object.__mod__(self, other) The Python __mod__() method implements the modulo operation % that per default returns the remainder of dividing the left by the right operand. Internally, Python attempts to call x.__mod__(y) to implement the modulo operation x%y. If the method is not implemented, Python first attempts to call __rmod__ on the right operand and … Read more

How to Develop LARS Regression Models in Python?

What is LARS regression? Regression is the analysis of how a variable (the outcome variable) depends on the evolution of other variables (explanatory variables). In regression, we are looking for the answer to the question of what is the function that can be used to predict the value of another variable Y by knowing the … Read more

[Google Interview] Shuffle the Array

[toc] Company Tags: Google, Adobe, Apple, Bloomberg, Microsoft Problem Description Given the array nums consisting of 2n elements in the form [x1, x2,…,xn, y1, y2,…, yn]. Return the array in the form [x1, y1, x2, y2,…, xn, yn]. Constraints: 1 <= n <= 500 nums.length == 2n 1 <= nums[i] <= 10^3 Examples Let’s have … Read more