How to Retrieve a Single Element from a Python Generator

This article will show you how to retrieve a single generator element in Python. Before moving forward, let’s review what a generator does. Quick Recap Generators πŸ’‘ Definition Generator: A generator is commonly used when processing vast amounts of data. This function uses minimal memory and produces results in less time than a standard function. … Read more

Plotly Dash Button Component – A Simple Illustrated Guide

Welcome to the bonus content of “The Book of Dash”. πŸ€— Here you will find additional examples of Plotly Dash components, layouts and style. To learn more about making dashboards with Plotly Dash, and how to buy your copy of “The Book of Dash”, please see the reference section at the bottom of this article. … Read more

Python – List of Lists to List of Strings. How?

Coding Challenge πŸ’¬ Coding Challenge: Given a nested Python list, i.e., a list of lists. How to convert it to a string list, so that each inner list becomes a single string? Consider the following examples: 1. Input: [[‘h’, ‘e’, ‘l’, ‘l’, ‘o’], [‘w’, ‘o’, ‘r’, ‘l’, ‘d’]] Output: [‘hello’, ‘world’] 2. Input: [[‘h’, ‘i’], … Read more

How to Stop a For Loop in Python

Python provides three ways to stop a for loop: The for loop ends naturally when all elements have been iterated over. After that, Python proceeds with the first statement after the loop construct. The keyword break terminates a loop immediately. The program proceeds with the first statement after the loop construct. The keyword continue terminates … Read more

Solidity Boolean and Integer Types – A Helpful Guide with Video

Types are among the most important building blocks of a statically-typed programming language, and since Solidity falls into that category, we finally have the opportunity to entertain ourselves with this crucial topic. By learning about types, we’ll get more closely familiar with the Solidity features that are based on idiosyncrasies of a particular data type. … Read more

Seven Simple Solidity Blocks to Build Your dApp

In this article, we’ll take a detailed look at the structure of a smart contract (docs). πŸ’‘ We’ll learn about state variables, functions, function modifiers, events, errors, struct types, and enum types. We have recognized most of these elements in action in the previous articles, especially in the ones where we had real examples of … Read more

Initialize a Huge Python Dict of Size N (Easy & Quick)

βš”οΈ Programming Challenge: Given an integer n that could be very high (e.g., n=1000000). How to initialize a Python dictionary of size n that is fast, easy, and efficient? Next, you’ll learn the five main ways to solve this and compare their performance at the end of this article. Interestingly, the winner Method 4 is … Read more

3 Best Ways to Generate a Random Number with a Fixed Amount of Digits in Python

Coding Challenge βš”οΈ Challenge: Given an integer d representing the number of digits. How to create a random number with d digits in Python? Here are three examples: my_random(2) generates 12 my_random(3) generates 389 my_random(10) generates 8943496710 I’ll discuss three interesting methods to accomplish this easily in Python—my personal favorite is Method 2! Shortest Solution … Read more