Month: March 2020

Python: How to Count Elements in a List Matching a Condition?

I stumbled across this question when browsing through StackOverflow and it got me thinking: what’s the best way to count the number of elements in a list that match a certain condition? Can you generalize this way to both general conditions (e.g. x>3) and regular expressions (e.g. ‘a.*’)? Short answer: you can count the number …

Python: How to Count Elements in a List Matching a Condition? Read More »

Python List index() – A Simple Illustrated Guide

This tutorial shows you everything you need to know to help you master the essential index() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.index(value) method returns the index of the value argument in the list. You can use optional start and stop arguments to limit …

Python List index() – A Simple Illustrated Guide Read More »

Python Regex Quantifiers – Question Mark (?) vs Plus (+) vs Asterisk (*)

In this tutorial, I’ll show you the difference of the regular expression quantifiers in Python. What’s the difference between the question mark quantifier (?), the plus quantifier (+), and the asterisk quantifier (*)? Say, you have regular expression pattern A. Regex A? matches zero or one occurrences of A. Regex A* matches zero or more …

Python Regex Quantifiers – Question Mark (?) vs Plus (+) vs Asterisk (*) Read More »