Integer division is an arithmetic operation where division is performed, but the remainder is discarded leaving us with just an integer.
In other programming languages, the combination of division plus something akin to a “floor” function is used to achieve similar results.
quotient = 8 / 3;
whole_number = Math.floor(quotient);console.log(whole_number); // prints 2
Having to round-down a normal division operation may not be particularly difficult, but it can be annoying and inconvenient. Fortunately, Python has us covered with the integer division operator.
Starting in version 3.10, one of my last grievances with Python — relative to other languages — is being addressed: the beloved switch statement.
In this article, we’ll introduce what switch statements are and how they are implemented in Python. Enjoy the tutorial and look forward to some refactoring!
For the uninitiated, a switch statement is a programming decision structure where one of multiple branches is executed…
In this article we’ll cover two separate algorithms to accomplish this and wrap up the guide with a recommendation for generalizing the strategy for easy repeated use.
Before we begin, here’s the data set we’ll be using. …
There are a multiple ways of removing duplicate values in an array. Before you jump into a recommended method, ask yourself what ES version are you working with?
We’ll go through three strategies to remove duplicate values. Each strategy will use newer conventions, resulting in more efficient code. For the sake of saving space, assume each code snippet uses a variable named items that is an array with some duplicate values.
This first method is battle-tested and guaranteed to work with even the oldest infrastructure.
We’ll begin by defining a new array to hold unique values and then use a…
I love Python’s flexibility. It’s elegant “ah-ha” moments where a clever implementation of native tools yields simplified results that put a smile on my face.
Recently, I had to analyze a data set — a list of dictionaries where one term named
status needed to be counted. I’ve done this in other languages before and had an algorithm which I had ported over to Python. But it dawned on me that there was a better way.
Before we jump into the algorithms, here’s a sample input and output to help frame the following solutions.
records = [
Don’t get the wrong idea from the featured image, I’m not advocating to consign your child to refresh duty.
If you’re anything like me then you’ve been locked up to varying degrees all year while anticipating all of the new tech that 2020 has to offer. Whether you’re interested in a Playstation 5, an XBox Series X, or next gen PC hardware, it doesn’t matter…you’re probably just as dejected and lost in the war against scalpers and bots as I am.
Well, fortunately I’ve found a solution to the problem that does not cost money, requires no technical skills, and…
Moving from simple command-line scripts to web app development is a big leap in our Python journey. There are a variety of framework options with; however, even the concept can be overwhelming if you’ve never worked with a web framework.
If you’ve found this article then you’re probably researching different Python frameworks and trying to decide which to invest in. Instead of suffering from analysis paralysis, take a leap of faith and jump into Flask with this guide.
The first step is the hardest to take, but the easiest to make .We’ll …
It’s natural to focus — and get stuck on — syntax, structures, and libraries when learning a new programming language. Especially if it’s your first language, learning how to manage an environment is normally filed away under blissful ignorance.
It’s possible (somewhat) to get quite far without tackling environment management, but once you hit a wall that requires it, you’ll be left looking at a disorganized system folder that can best be described as a cluster****.
To start building good habits early, introduce Python virtual environments. …
Node.js as a JS runtime environment has become an absolute backbone for technology stacks. Any time you see the letter “N” in a tech stack, such as MEAN, that’s most likely Node.
With great success comes longevity and with longevity comes legacy challenges, some of which are too deeply ingrained in the architecture to be addressed.
There are a variety of reasons to count backwards in a program. Maybe you want to iterate over a list starting from the end or simply want to display a countdown timer.
We have multiple options available to us and are going to introduce two of those options: manually modifying a counter variable and using the
The most basic method of counting backwards is to use a counting variable inside of a while loop. We need three definitions in order to count backwards: the starting point, how to exit the loop, and how to modify the loop.