Regex

The Most Pythonic Way to Check if a Python String Contains Another String? (Tutorial + Video)

How to check if a Python string s1 contains another string s2? There are two easy ways to check whether string s1 contains string s2: Use the expression s2 in s1, or Use the find method s1.find(s2). You can try both methods in our interactive Python shell (just click “Run” to execute the code in …

The Most Pythonic Way to Check if a Python String Contains Another String? (Tutorial + Video) Read More »

Python Lists filter() vs List Comprehension – Which is Faster?

[Spoiler] Which function filters a list faster: filter() vs list comprehension? For large lists with one million elements, filtering lists with list comprehension is 40% faster than the built-in filter() method. To answer this question, I’ve written a short script that tests the runtime performance of filtering large lists of increasing sizes using the filter() …

Python Lists filter() vs List Comprehension – Which is Faster? Read More »

How to Match an Exact Word in Python Regex? (Answer: Don’t)

This morning, I read over an actual Quora thread with this precise question. While there’s no dumb question, the question reveals that there may be some gap in understanding the basics in Python and Python’s regular expression library. So if you’re an impatient person, here’s the short answer: How to match an exact word/string using …

How to Match an Exact Word in Python Regex? (Answer: Don’t) Read More »

Regex Special Characters – Examples in Python Re

Regular expressions are a strange animal. Many students find them difficult to understand – do you? I realized that a major reason for this is simply that they don’t understand the special regex characters. To put it differently: understand the special characters and everything else in the regex space will come much easier to you. …

Regex Special Characters – Examples in Python Re Read More »

Python Re Groups

This tutorial explains everything you need to know about matching groups in Python’s re package for regular expressions. You may have also read the term “capture groups” which points to the same concept. As you read through the tutorial, you can also watch the tutorial video where I explain everything in a simple way: Related …

Python Re Groups Read More »