Python Int to String with Leading Zeros

To convert an integer i to a string with leading zeros so that it consists of 5 characters, use the format string f'{i:05d}’. The d flag in this expression defines that the result is a decimal value. The str(i).zfill(5) accomplishes the same string conversion of an integer with leading zeros. Challenge: Given an integer number. … Read more

How To Extract Numbers From A String In Python?

The easiest way to extract numbers from a Python string s is to use the expression re.findall(‘\d+’, s). For example, re.findall(‘\d+’, ‘hi 100 alice 18 old 42’) yields the list of strings [‘100′, ’18’, ’42’] that you can then convert to numbers using int() or float(). There are some tricks and alternatives, so keep reading … Read more

How to Count the Number of Words in a String in Python

Problem Formulation Given a string – sentence. How many words does the string sentence have within it? Examples: INPUT sentence = “Finxter helps you to master Python.” OUTPUT Number of words: 6 INPUT sentence = “””Lorem ipsum dolor sit amet. Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.””” OUTPUT … Read more

Motion Detection Using OpenCV in Python – My journey through to a successful project

Motion detection algorithms form an important part of a video surveillance system. It can also be coupled with many AI-based human presence and profiling systems. Many applications of motion detection algorithms may be thought of with substantive advantages in saving man-hours, efforts, and storage requirements, that is: Out of my sheer personal experience, which I … Read more

5 Easy Ways to Download an Image from a URL in Python

Problem Formulation and Solution Overview In this article, you’ll learn how to download an image from the web in Python. To make it more fun, we have the following running scenario: Sven, a Journalist from Greeland, is writing about Glacier Calving. His editor would like photos of iceberg collapses in the area accompanying his article. … Read more

Data Science Tells This Story About the Global Wine Markets 🍷

πŸ“– Background Many people like to relax or party with a glass of wine. That makes wine an important industry in many countries. Understanding this market is important to the livelihood of many people. For fun, consider the following fictional scenario: 🍷 Story: You work at a multinational consumer goods organization that is considering entering … Read more

ChatGPT at the Heart – Building a Movie Recommendation Python Web App in 2023

In this article, I will show you how I have built a simple but quite powerful movie recommendation app. πŸ’» Try It Yourself: You can play with the live demo here. I built it for two reasons: This app uses Python, HTML/CSS, Flask, Vercel, and the OpenAI API capabilities. Prerequisites Files in this project Here … Read more

I Made a Password Generator in Streamlit That’s Really Secure (Maybe Too Secure!)

Project Description Both in my day job and personal life, I notice every day how important online security has become. Almost every part of our everyday lives are connected somehow to the Internet. And everyone of those connections requires (or should need) a password at the least. The problem with that is that passwords are … Read more