How to Send UDP Messages in Python?

Problem Formulation: How to send and receive UDP messages in Python? Background: The User Datagram Protocol (UDP) network layer allows you to send messages without providing deliverability guarantees. UDP is unreliable—massages may be lost or delivered out of order. But this makes UDP also fast, lightweight, and the protocol of choice for many streaming scenarios … Read more

How to Remove Everything After the Last Character in a String?

Problem Formulation Given string s, and character c. How to remove all characters in s after the first occurrence of c? Example Given: – string s = ‘hello world’, and – empty space character c = ‘ ‘. Desired result: ‘hello’ Method 1: string.index() + slicing To remove everything after the first occurrence of character … Read more

How To Cut A String In Python?

Problem: Given a string; how to split/cut the string and extract the required characters? In this article, we will be discussing some interesting scenarios which allow us to split or cut a string and extract the necessary portion of the string that we need. Let us dive into each example/scenario and have a look at … Read more

How to Remove a Non-Empty Folder in Python?

Problem Formulation: Given a path to a folder as a Python string. The folder is non-empty. How to remove the whole folder in your Python script? Example: Say, you have the path=’path/to/folder’ in your Python script and it contains some files and subfolders: path –to —-folder ——file1.dat ——file2.dat ——subfolder1 ——–file3.dat ——subfolder2 ——–file4.dat You want to … Read more

What is a Hypergraph?

First, let’s have a look at an image—hopefully telling us more than a thousand words: Okay, let’s go back to square one—before you understand hypergraphs, we first need to understand graphs. What Are Graphs? You most likely know graphs. The web graph consists of websites connected via hyperlinks. The websites are graph vertices and the … Read more

Python filter()

Python’s built-in filter() function is used to filter out elements that pass a filtering condition. It takes two arguments: function and iterable. The function assigns a Boolean value to each element in the iterable to check whether the element will pass the filter or not. It returns an iterator with the elements that pass the … Read more

How to Fix “TypeError: len() of unsized object”

Problem Formulation: How to fix the TypeError: len() of unsized object? TypeError: len() of unsized object There are many possible ways why this array may occur. One common pitfall is to use the len() function on a NumPy array with only one value. Example: Let’s consider the minimal example that creates this error message! Reason … Read more

How to Install a Library on PyCharm?

Problem Formulation: Given a PyCharm project. How to install a library in your project within a virtual environment or globally? Solution that always works: Open File > Settings > Project from the PyCharm menu. Select your current project. Click the Python Interpreter tab within your project tab. Click the small + symbol to add a … Read more