If you been into development for sometime, you’ve probably heard the term “API” or “REST API” or “RESTful API”. If you’re wondering what they mean, this article helps you understand these terms, how to use a REST API and why REST APIs they’re important.
What is an API?
To build interactive and scalable applications, it is natural for programs to be able to communicate with each other. An API (shorthand for Application Programming Interface) is a set of rules to facilitate this communication between different programs. …
A Medium Difficulty Problem from Leetcode
Sum Root to Leaf Numbers is an interesting problem from Leetcode. The problem is of medium difficulty and is about binary trees. This post is an explained solution to the problem.
I assume that you’re familiar with Python and the concept of binary trees. If you’re not, you can read this article to get started.
Given a binary tree whose nodes contain values 0-9
, we have to find the sum of all numbers formed by root-to-leaf paths. A leaf is a node that doesn’t have any child nodes. In a binary tree, a root-to-leaf path is always unique. …
If you’ve been programming for a while, you’ve probably heard about garbage collection. Let’s delve deeper into what it is and how it works.
In the real world, we clear out things — e.g., old notes, boxes that we no longer need — and discard them in a garbage/recycling can. Space is limited, and we want to make space for other essential items we want to store.
Similarly, in computers, space — aka memory — is an important and finite resource. Thus, a garbage collector collects data objects that are no longer needed and discards them.
Depending on the language, garbage collection can be an automatic or a manual process. In most high-level languages, such as Python and Java, it’s automated. Thus, these languages are called garbage-collected languages. Other languages, such as C, don’t support automatic garbage collection, and the programmer is responsible for memory management. …
Often times, we work with strings and want to quickly check if they are of a particular type or contain specific data. While we can do the same by either storing the characters of the string in a data structure or explicitly writing down statements to verify, string validators in Python can simplify our task. This can be useful when validating a password string or any other user input. String validators are essentially functions that allow us to check if a string meets certain criteria.
This post is an introduction to string validators and assumes no prior knowledge of them. Basic prior knowledge of programming in Python, however, is expected. …
What is a Priority Queue?
A queue has FIFO (first-in-first-out) ordering where items are taken out or accessed on a first-come-first-served basis. Examples of queues include a queue at a movie ticket stand, as shown in the illustration above. But, what is a priority queue?
A priority queue is an abstract data structure (a data structure defined by its behaviour) that is like a normal queue but where each item has a special “key” to quantify its “priority”. For example, if the movie cinema decides to serve loyal customers first, it will order them by their loyalty (points or number of tickets purchased). In such a case, the queue for tickets will no longer be first-come-first-served, but most-loyal-first-served. …
Recently, the use of functional programming has been on the rise. Thus, many traditionally imperative languages like Java and Python have started to support functional programming techniques.
This article is an introduction to these functional programming techniques in Python. This article assumes basic knowledge of functional programming. If you’re unfamiliar with functional programming, check out this article on FP.
In Python, functions are first-class. This implies that they can be treated as just another data type, such as int
.
Thus, we can assign them to variables, pass them as arguments to other functions, store them in other data structures such as dicts
, and use them as return values for other functions. …
A 2 min summary of the Turing Test and why it works
How can we ascertain that machines can think? In Computing Machinery and Intelligence, 20th-century Computer Scientist Alan Turing argues that The Imitation Game, a thought experiment, is sufficient to determine a machine’s thinking ability.
The Imitation Game is played by three players: a man (A), a woman (B) and an interrogator (C). A and B are in a different room from C, whose objective is to determine the gender of A and B by asking questions and getting answers via typed notes. …
The secret to affordable international travel
Disclaimer: I am not a promoter of the bank I recommend nor is this review sponsored by any organisation. This review is independent and purely for the knowledge of the general audience. The links in this article are not affiliate links.
When we want to convert between currencies, we often turn to Google (or any other currency converter) for the same:
If Python was a story, assertions would be one of the unsung heroes. Chances are that you may not have heard about them and what they can do. So, let’s get started!
Assertions or assert statements are built into Python and are a tool for debugging. An assert statement, as the name may suggest, tries to assert its authority over the rest of the code when checking for a condition specified by the programmer.
For example, you could tell the assert statement to check if the value of the variable speed
is greater than or equal to 0
(since velocity can be negative but not speed). If the condition is true, assert doesn’t do anything and the program runs normally. However, if the condition fails, the assert statement asserts its authority and raises an AssertionError
, which stops the execution of the program. …
Think filling out forms on the web is boring and tedious? I cannot agree with you more. I’m writing this post to document the process of creating a Telegram Bot to automate a web process and demonstrate how we could save time and effort by using programming to automate simple tasks. Let’s get started!
Motivation and Idea💡
About