Python filter() function examples

March 5, 2021 A Goodman

In this article, we will cover the fundamental of the filter() function in Python and explore 4 practical examples of using it. Overview Syntax: Paramerters: function: The function that tests whether each item of an iterable…

Examples of using map() function in Python 3

March 4, 2021 A Goodman

In this article, we’ll go over a few examples of using the map() function in Python 3. Overview Syntax: function: The function to execute for each item iterables: one or many iterables (lists, tuples, etc). The…

Examples of using Lambda Functions in Python 3

February 10, 2021 The Plumber

A lambda function in Python is a small anonymous function that is defined by using the lambda keyword, like this: A lambda function can take unlimited number of arguments but it is syntactically restricted to a…

VS Code: How to comment out a block of Python code

January 7, 2021 The Plumber

To comment out a line of code in Python, you can add a # before that line. So how to comment out a block of code in Python? If you have worked with some other programming…

Examples of numpy.linspace() in Python

December 12, 2020 The Plumber

The numpy.linspace() function returns an ndarray with equally spaced intervals between the start and stop values. That ndarray is a vector space, also known as a linear space. That’s why the function is named linspace. This…

Extract all links from a webpage using Python and Beautiful Soup 4

February 9, 2021 The Shadow

This article shows you how to get all links from a webpage using Python 3, the Requests module, and the Beautiful Soup 4 module. For the demonstration purpose, I will scrape and extract the main page…

Most popular String methods in Python

February 9, 2021 The Plumber

Python provides a lot of methods that help programmers easily and quickly modify and manipulate strings. Learning all of these methods by heart is a hard job that takes much time and effort, and you may…

Python3.9 malloc error: can’t allocate region

November 23, 2020 A Goodman

Problem When running Python code that imports some modules (request, numpy, pandas, etc), I fall into the following error: This happens with both global and virtual environment. More error messages: My environment: Solution If you run…

Python program to count lower case letters in a string

November 4, 2020 Guest Contributor

To check if a letter is lower case or not in Python, we can use the islower() method. Combine it with a for loop, we can easily count the number of lower case letters in a…

Python program to count all capital letters in a string

November 4, 2020 Guest Contributor

The following Python program counts the number of capital letters in a string. The code: Output: That’s it. Happy coding with Python 🙂

Python program to count files inside a folder

November 3, 2020 A Goodman

The Python program below counts the number of files inside a folder. Program folder structure: Note that the photos folder contains 11 files and 1 empty folder named empty. The code and explanation: Output:

Python: Count words in a string using Regular Expression

November 3, 2020 Guest Contributor

The Python program below counts the number of words in a given string. Whitespace and any special symbols except the underscore will be ignored. Output:

1 2 3