Month: March 2020

Python List sort() – The Ultimate Guide

Every computer scientist loves sorting things. In this article, I’ll show you how Python does it—and how you can tap into the powerful sorting features of Python lists. Definition and Usage: The list.sort() method sorts the list elements in place in an ascending manner. To customize the default sorting behavior, use the optional key argument …

Python List sort() – The Ultimate Guide Read More »

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 »