How to Create a Sequence of Linearly Increasing Values with Numpy Arange?

Problem: How to create a sequence of linearly increasing values? Solution: Use NumPy’s arange() function. The np.arange([start,] stop[, step]) function creates a new NumPy array with evenly-spaced integers between start (inclusive) and stop (exclusive). The step size defines the difference between subsequent values. For example, np.arange(1, 6, 2) creates the NumPy array [1, 3, 5]. … Read more

How to Find the Maximum Value in a Python Dict?

There are three problem variants of finding the maximum value in a Python dictionary: In the following, you’ll learn how to solve those in the most Pythonic way: Find Maximum Value & Return Only Value The output is: Find Maximum Value & Return (Key, Value) Pair The output is: Find Maximum Value & Return Only … Read more

How to Sort a Dictionary in Python By Key?

To sort a dictionary by key in Python, use the dictionary comprehension expression {key:dict[key] for key in sorted(dict)} to create a new dictionary with keys in sorted order. You iterate over all keys in sorted order, obtain their associated values with rank[key], and put them into a new dictionary. Python dictionaries preserve the order—even if … Read more

The Pathfinder Graph Algorithm in Python

Knowing the basics is what sets apart the great from the intermediate coders. In other words, a simple and effective way to grow your skills is to learn the basics of computer science. Python Pathfinder Algorithm In this tutorial, you’ll learn about the pathfinder algorithm that recursively determines whether there’s a direct or indirect path … Read more

Decision Tree Learning — A Helpful Illustrated Guide in Python

This tutorial will show you everything you need to get started training your first models using decision tree learning in Python. To help you grasp this topic thoroughly, I attacked it from different perspectives: textual, visual, and audio-visual. So, let’s get started! Why Decision Trees? Deep learning has become the megatrend within artificial intelligence and … Read more

The Quicksort Algorithm in Python

For a coder, understanding the Quicksort algorithm is like knowing the secret of 42—either you get it, or you don’t belong to the club. If you don’t know either, let’s work on the first one! The Quicksort Algorithm — A Python Implementation The algorithm is a variant of the popular Quicksort algorithm. The function qsort … Read more

29+ Killer Resources on Learning Python [Collection]

Python is one of the most popular programming language according to a recent IEEE Spectrum article. In this article, we compiled the best resources to learn Python for you— whether you’re a beginner, intermediate, or professional Python developer. ALL LINKS OPEN IN A NEW TAB! Python and Computer Science Puzzles Cheat Sheets Online Tutorials Online … Read more

The Matrix Find Algorithm in Python

Challenge: How to find an element in a sorted matrix where row and column values increase monotonically? What is a matrix? A matrix is a table of values consisting of rows and columns. Here, we represent the matrix as a list of integer lists. Hence, we can access matrix values with the indexing and slicing … Read more