How to Generate a Random Date Between Two Dates in Python?

Problem Formulation and Solution Overview This article will show you how to generate a random date between two dates in Python. πŸ’¬ Question: How would we write code to generate a random date between two dates? We can accomplish this task by one of the following options: Method 1: Use datetime.timedelta() and random.random() Method 2: … Read more

About Chris

Welcome to the Finxter blog! My name is Chris, and I started this coding venture a couple of years ago. Check out this podcast generated by NotebookLM about my journey: Over the years, I have chatted with tens of thousands of Finxters who shared their stories and struggles with me. πŸ‘‰ See here and here to … Read more

Solidity Contract Types, Byte Arrays, and {Address, Int, Rational} Literals

With this article, we continue our journey through the realm of Solidity data types following today’s topics: contract types, fixed-size byte arrays, dynamically-sized byte arrays, address literals, rational, and integer literals. 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. πŸ‘‡ … Read more

(Solved) Python TypeError ‘Method’ Object is Not Subscriptable

The β€œTypeError: ‘method’ object is not subscriptable” occurs when you call a method using square brackets, e.g., object.method[3]. To fix it, call the non-subscriptable method only with parentheses like so: object.method(3). How Does the Error Occur (Example) In the following minimal example, you attempt to define a custom “list” class and you try to access … Read more

How to Sum the Digits of a Number in Python?

Problem Formulation Given an integer number. How to sum over all digits of this number to compute the crossfoot (cross total)? Consider the following examples: 12 –> 1+2 = 3 123 –> 1+2+3 = 3 244 –> 2+4+4 = 10 981223 –> 9+8+1+2+2+3 = 25 Method 1: sum() with Generator Expression The Python built-in sum(iterable) … Read more

Python Time Series Forecast on Bitcoin Data (Part II)

A Time Series is essentially a tabular data with the special feature of having a time index. The common forecast taks is ‘knowing the past (and sometimes the present), predict the future’. This task, taken as a principle, reveals itself in several ways: in how to interpret your problem, in feature engineering and in which … Read more

How to Subtract Two Python Lists (Element-Wise)?

Problem Formulation and Solution Overview This article will show you how to subtract two Lists in Python. πŸ’‘ Note: Before subtracting these Lists, ensure each List is of the same length and contains subtractable data. For example, subtracting a List of strings from a List of integers or floats will result in an error. Whereas … Read more

How to Concatenate a Boolean to a String in Python?

Easy Solution Use the addition + operator and the built-in str() function to concatenate a boolean to a string in Python. For example, the expression ‘Be ‘ + str(True) yields ‘Be True’. The built-in str(boolean) function call converts the boolean to a string. The string concatenation + operator creates a new string by appending the … Read more

(Fixed) Python TypeError ‘bool’ object is not subscriptable

Problem Formulation Consider the following minimal example where a TypeError: ‘bool’ object is not subscriptable occurs: This yields the following output: Solution Overview Python raises the TypeError: ‘bool’ object is not subscriptable if you use indexing or slicing with the square bracket notation on a Boolean variable. However, the Boolean type is not indexable and … Read more

Python Scrapy – Scraping Dynamic Website with API-Generated Content

Scrapy is an excellent tool for extracting data from static and dynamic websites. In this article, we are going to discuss the solution to the following problems: Extract all details of Offices from the website https:/directory.ntschools.net/#/offices Instead of using a whole scrapy framework, use a typical Python script for extracting the data. For each office, … Read more

How to Determine Script Execution Time in Python?

Problem Formulation and Solution Overview This article will show you how Python can determine a script’s execution time. Let’s say you have written several code sections. Each section performs identical tasks. How could you best determine which section works faster and more efficiently? πŸ’¬ Question: How would we write code to determine a script’s execution … Read more