Python
-
How to Compare Two Strings in Python (in 8 Easy Ways)
Comparing strings is a fundamental task common to any programming language. When it comes to Python, there are several ways of doing it. The...
-
Pylint: How to fix "c0209: formatting a regular string which could be a f-string (consider-using-f-string)"
Some weeks I ago I faced this problem in one of my projects after upgrading pylint to 2.11 . The error was: script.py:7:8: C0209:...
-
Python pathlib Cookbook: 57+ Examples to Master It (2022)
When I started learning Python, there was one thing I always had trouble with: dealing with directories and file paths! I remember the struggle...
-
How to Disable Autouse Fixtures in pytest
pytest is a very robust framework that comes with lots of features. One such feature is the autouse fixtures, a.k.a xUnit setup on...
-
15 Easy Ways to Trim a String in Python
I'm not gonna lie. There are multiple ways you can trim a string in Python. But... the truth is, you don't need to know every one of them. In...
-
How to Choose Between isdigit(), isdecimal() and isnumeric() in Python
In this post, you'll learn the subtle difference between str.isdigit , str.isdecimal , and str.isnumeric in Python 3 and how to choose the...
-
One Year of Blogging
On the 31st of Aug 2020, I published my first ever blog post. Its been a wild journey, full of ups and downs, but a very rewarding one. In this...
-
How I Patched Python to Include This Ruby Feature
In this post, I'll present how I changed Pythons source code and compiled from scratch to accept "else-less" if expressions, similar to Ruby's...
-
11 Useful Resources To Learn Python's Internals From Scratch
"How does Python work internally?" I have been asking myself that question for the past few months and now it seems that I'm starting to grasp,...
-
How to Implement a Random String Generator With Python
In this post, you'll learn how to create a random string in Python using different methods; but, beware! Some of them only work with Python 3.6+....
-
How to Sort a Dict in Descending Order by Value With Python
In this post, you will learn how to sort a Python dictionary by value descending i.e. in reverse order. Say that you have the following...
-
How to Check If a String Is a Valid URL in Python
How to check if a URL is valid in python? You'll be surprise how easy it is to check that. In this article you'll learn how to determine if a...
-
How to Find the Current Working Directory in Python
Python provides two different ways to get the current working directory. The first method uses the os module and the second uses the newer...
-
7 Different Ways to Flatten a List of Lists in Python
Ever wondered how can you flatten, or unnest, a 2D list of lists in Python? In another words, how to turn 2-D lists into 1D: [[1, 2], [3,...
-
Design Patterns That Make Sense in Python: Simple Factory
In the first post of this series, I'll talk about Design Patterns that make sense in Python. We'll see how to implement them and how they are used...
-
How to Pass Multiple Arguments to a map Function in Python
Introduction The map() function is everywhere in Python. It's a built in, it's part of the concurrent.futures.Executor , and also...
-
How to Use Fixtures as Arguments in pytest.mark.parametrize
TL;DR Time is a precious resource so I won't waste yours. In this post, you'll learn how to use a pytest fixture in parametrize using a library...
-
How to Use datetime.timedelta in Python With Examples
In this tutorial, you'll learn how to use datetime.timedelta to perform date arithmetic. With timedelta you can add days, minutes, seconds,...
-
Python F-String: 73 Examples to Help You Master It
Python f-strings are impressive! Did you know you can use f-strings to string format almost anything in Python? You can use them to format...
-
How to Check if an Exception Is Raised (or Not) With pytest
TL;DR Time is a precious resource so I won't waste yours. Here's how you can assert an exception is raised and how to check that in pytest ....
-
Python Gotchas: 5 Worst Mistakes You Should Avoid
Have you ever had a bug that took ages to fix and made no sense at all? If the answer is yes, then keep reading. Chances are that if you...
-
The Best Way to Compare Two Dictionaries in Python
When I had to compare two dictionaries for the first time, I struggleda lot! For simple dictionaries, comparing them is usually straightforward....
-
5 Hidden Python Features You Probably Never Heard Of
In this article, Im going to show you the top 5 hidden features you can find in Python. Experienced Python developers might recognize some of...
-
7 pytest Features and Plugins That Will Save You Tons of Time
pytest is a powerful testing framework. When used correctly, it makes tests concise, easy to follow and maintain. What few people know is that...
-
Hacktoberfest: 69 Beginner-Friendly Projects You Can Contribute To
Wanna get started in open source and also score some nice swags? Join the Hacktoberfest 2020! In this post, Ill list 69 beginner-friendly...