In a previous article — Three Easy Ways to Remove Duplicate Array Values in JavaScript—we covered three different algorithms to create an array of unique values. The most common request that came from that article was a similar mechanism for a key in an array of objects.
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 = [ { "id": 1…
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. …
Dating back to Node.js creator Ryan Dahl’s 2018 presentation 10 Things I Regret about Node.js, the programming community was anticipating his latest creation. Fast forward to May 2020 and Deno — A secure runtime for JavaScript and TypeScript — has released version 1.0.
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.
This…
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 range()
function.
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.
Let’s…
Create a function that converts a list to a two-dimensional “list of lists” where each nested structure is a specified equal length.
Here are some example inputs and expected outputs:
# INPUT LIST: [1,2,3,4,5,6]
# INPUT SIZE: 3
# OUTPUT: [[1,2,3],[4,5,6]]# INPUT LIST: [1,2,3,4,5]
# INPUT SIZE: 2
# OUTPUT: [[1,2],[3,4],[5]]# INPUT LIST: [1,2,3]
# INPUT SIZE: 4
# OUTPUT: [[1,2,3]]
Reviewing our examples, there are some important distinctions for scenarios where the list and chunk size do not perfect match up.
Python provides a native library for passing command-line values to scripts called argparse. With argparse, we can include variable values in the execution command instead of using input() to request the value mid-execution. This saves us time and more importantly allows script execution lines to be saved and conveniently used — either manually or automated.
If you’ve written any Python scripts that require one or two values via input(), then read on and consider implementing argparse to simplify the execution of your scripts. …