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

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

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

A Recursive Pathfinder Algorithm in Python

A simple and effective way to grow your computer science skills is to master the basics. Knowing the basics sets apart the great coders from the merely intermediate ones. One such basic area in computer science is graph theory, a specific subproblem of which—the pathfinder algorithm—we’ll address in this tutorial. So first things first: What … 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 Calculate the Average of a NumPy 2D Array?

NumPy is a popular Python library for data science focusing on arrays, vectors, and matrices. This article introduces the np.average() function from the NumPy library. When applied to a 1D array, this function returns the average of the array values. When applied to a 2D array, NumPy simply flattens the array. The result is the … 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

29+ Killer Resources on Learning Python [Collection]

Python is one of the most popular programming language according to a recent IEEE Spectrum article. In this article, we compiled the best resources to learn Python for you— whether you’re a beginner, intermediate, or professional Python developer. ALL LINKS OPEN IN A NEW TAB! Python and Computer Science Puzzles Cheat Sheets Online Tutorials Online … 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. A Python tuple is an immutable, ordered, and iterable container data structure that can hold arbitrary and heterogeneous immutable data elements. Tuple Motivating Example … 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.