How to Switch Keys and Values in a Python Dictionary?

Problem: Given a dictionary in Python; how to switch Keys and Values?  Method 1: Using a for loop   Method 2: Using the zip function Method 3: Using the map and reverse functions Method 4: Using a dictionary comprehension Summary: Use one of the following methods to switch between the keys and values in a dictionary with unique values. … Read more

How to Calculate Percentiles in Python

This article deals with calculating percentiles. Percentiles are statistical indicators that are used to describe specific portions of a sample population. The following sections will explain what percentiles are, what they are used for and how to calculate them, using Python. As you will see, Python allows solving this problem in multiple ways, either by … Read more

Python frozenset() — A Simple Guide with Video

Python’s built-in frozenset() function creates and returns a new frozenset object. A frozenset is an immutable set—so you cannot change the frozenset after creation and set methods such as add() or remove() don’t work on the frozenset. Without an argument, frozenset() returns an empty frozenset. With the optional argument, frozenset(iter) initializes the new frozenset with … Read more

My Business and Coding Book Recommendations

“Readers are leaders.” Many Finxters seek mentorship—and write in asking me for book recommendations. I read about one business or programming book per week and this simple habit has completely transformed my life. In this article, I’ve compiled my top list of business and programming books—ordered by how great I think the book is. All … Read more

Python set() Function — A Simple Guide with Video

Python’s built-in set() function creates and returns a new set object. A set is an unordered collection of unique elements. Without an argument, set() returns an empty set. With the optional argument, set(iter) initializes the new set with the elements in the iterable. Read more about sets in our full tutorial about Python Sets. Usage … Read more

How to Index 1D NumPy Arrays?

Numpy is a popular Python library for data science focusing on arrays, vectors, and matrices. Problem Formulation: Given a one-dimensional NumPy array arr. How to access the i-th value in the array? How to access all values between the i-th value (included) and the j-th value (excluded) from the array? How to access all values … Read more

Linked Lists in Python

In this blog post you will learn how to implement a linked list in Python from scratch. We will understand the internals of linked lists, the computational complexity of using a linked list and some advantages and disadvantages of using a linked list over an array. Introduction Linked list is one of the most fundamental … Read more

Python format() Function: No-BS Guide by Example

The web is filled with shitty tutorials about Python’s formatting feature. At times, it can become really confusing—and it’s hard to see the forest for the trees. In this tutorial, I’ll try to gradually build a basic understanding of the built-in format() function, what it does, and how you can use it to become a … Read more

The K-Means Algorithm in Python

Hey Finxters! Today we are going to talk about one of the most popular clustering algorithms: K-Means. Ever wondered how to organize seemingly unstructured data, making sense of unordered objects, in an easy way? For example, you might need to: perform customer segmentation store files based on their text content compress images with your own … Read more

Python float() Function

Python’s built-in float(value) function converts the argument value to a float number. For example, float(’42’) converts the string value ’42’ into the float number 42.0. Argument value A Python object to be converted into a float number. The value object must have an __float__() method that returns the associated float number—otherwise a ValueError will be … Read more

Python int() Function

Python’s built-in int(value) function converts the argument value to an integer number. For example, int(’42’) converts the string value ’42’ into the integer number 42. The int() function on a float argument rounds down to the closest integer. Argument value A Python object to be converted into an integer number. The value object must have … Read more