Python | Split String by Newline

Summary: Use given_string.splitlines() to split a given string by newline. Minimal Example: Problem Formulation πŸ“œProblem: Given a string, How will you split the string into a list of words using newline as a separator/delimiter? Example: Let’s dive into the different ways of solving the given problem. Method 1: Using splitlines Approach: The easiest way to split a … Read more

Python | Split String by Comma and Whitespace

Summary: To split a string by comma and whitespace, you can use a list comprehension that splits the given string by comma and then eliminate the whitespaces from the substrings using the strip method. Minimal Example: Note that there are different scenarios and many other ways of solving the problem. Please read ahead to discover … Read more

Python Create List of Objects

You can create a list of objects using the list comprehension statement [MyObject() for _ in range(n)] that repeats n times the creation of a new object using the MyObject() constructor. The result is a list of n new objects (not copies). Here’s a minimal example: You can see that all of them point to … Read more

How to Get the First Character of a String

Problem Formulation and Solution Overview This article will show different ways to extract the first character of a Python string. To make it more interesting, we have the following scenario: The Government has asked Rivers Clothing to complete forms for each employee. These forms require the first character of the employee’s first name and their … Read more

Python | Split String and Get Last Element

Summary: Use given_string.rsplit(‘sep’, 1)[-1] to split the string and get the last element. Another approach is to use given_string.rpartition(‘sep’, 1)[-1] Minimal Solution: Problem Formulation πŸ“œProblem: Given a string. How will you split the string and get the last element? Let’s try to understand the given problem with the help of an example: Example 1 In … Read more

Python bytes vs bytearray

What’s the Difference Between bytes() and bytearray()? The difference between bytes() and bytearray() is that bytes() returns an immutable and bytearray() returns a mutable object. So you can modify a bytearray but not bytes type. Here’s a minimal example that nicely demonstrates the difference of the two functions: You create two variables a and b. … Read more

Working with Markdown Files in Python

This article will show you how to create and work with markdown files using Python. πŸ’‘ Markdown is an excellent tool with many features to spice up a flat-text file, such as changing text colors, adding bullet points, tables, and much more. A terrific way to add pizzazz to an otherwise dull file. To make … Read more

Solidity Operators and ‘Delete’ Keyword

Throughout this article, we’ll take a dive into the topics of operators, specifically the ternary operator, compound and increment/decrement operators, and the delete keyword. We’ll conclude the article with a table overviewing the operators in Solidity. It’s part of our long-standing tradition to make this (and other) articles a faithful companion or a supplement to … Read more

Solidity Iterable Mapping Type (Howto + Video)

In this article, we’ll continue our story on the mapping data structure, but this time, we’ll go through the data structure upgrade and reach a new functionality: the iterative mapping data structure. This way, by upgrading the readily available data structure, we’ll get a broader perspective and better understanding of how it works and how … Read more

Solidity Mapping Type Made Easy [+Video]

In this article, you’ll dive into detail on the Solidity mapping type and learn about mapping type specifics. It’s part of our long-standing tradition to make this (and other) articles a faithful companion, or a supplement to the official Solidity documentation, starting with docs for this article’s topic. Mapping Type We have seen mapping type … Read more