Python endswith() Tutorial – Can We Use Regular Expressions?

While refactoring my Python code, I thought of the following question. Can You Use a Regular Expression with the Python endswith() Method? The simple answer is no because if you can use a regex, you won’t even need endswith()! Instead, use the re.match(regex, string) function from the re module. For example, re.match(“^.*(coffee|cafe)$”, tweet) checks whether … Read more

You Cannot Use Python Regex in startswith(). Do This Instead.

I’m sitting in front of my computer refactoring Python code and have just thought of the following question: Can You Use a Regular Expression with the Python string.startswith() Method? The short answer is no. The string.startswith() method doesn’t allow regular expression inputs. And you don’t need it because regular expressions can already check if a … Read more

NumPy arange(): A Simple Illustrated Guide

The np.arange() function appears in 21% of the 35 million Github repositories that use the NumPy library! This illustrated tutorial shows you the ins and outs of the NumPy arange function. So let’s get started! What’s the NumPy Arange Function? The np.arange([start,] stop[, step]) function creates a new NumPy array with evenly-spaced integers between start … Read more

How to Calculate the Weighted Average of a Numpy Array in Python?

Numpy Weighted Average np.average(array, axis=0, weights=[0.1,0.1,0.8])

Problem Formulation: How to calculate the weighted average of the elements in a NumPy array? Definition weighted average: Each array element has an associated weight. The weighted average is the sum of all array elements, properly weighted, divided by the sum of all weights. Here’s the problem exemplified: Quick solution: Before we discuss the solution … Read more

How to Index Elements in NumPy Arrays?

NumPy is a popular Python library for data science for array, vector, and matrix computations. This puzzle introduces basic indexing of elements in NumPy arrays. Problem Formulation: How to index elements in NumPy arrays? Indexing 1D Arrays with Positive Indices The most simple use of indexing is with the square bracket notation and positive integers: … Read more

How to Calculate the Standard Deviation in NumPy?

Problem Formulation: How to calculate the standard deviation in NumPy? Differentiations: There are many different variants of this problem: Calculate the standard deviation of a 1D array Calculate the standard deviation of a 2D array Calculate the standard deviation of a 3D array Then you can also calculate the standard deviation along an axis: Calculate … Read more

The Ultimate Guide To Python Tuples

Python has several built-in data structures such as Lists, Sets and Dictionaries (check out the articles!).In this article, you’ll learn everything you need to know about tuples including real world examples. Tuple Motivating Example Did you ever have a function from which you wanted to return several values? Say, you’ve got a function translate(text, target_language) … Read more

How to Become a Python Freelancer—and Earn $1,000 on the Side? [A Step-by-Step Tutorial]

Pyhton Freelancer

Do you want to earn money as a Python freelancer? But you just start out learning Python? This article leads you step-by-step through the adventure of becoming a Python freelancer. Learn about the exact steps you need to do to become a Python freelancer – starting out as a Python newbie. Without losing any time, let’s dive into the 7 steps of becoming a Python freelancer.