Extract Strings from a List in Python

extract string from list python

As a developer, I was working on a project where I had to clean up a dataset that mixed numbers, strings, and special characters in the same list. So, I had to rely on different Python tricks and methods I’ve learned over the years. In this tutorial, I’ll share those methods with you. I’ll show … Read more >>

Get All Values from a Dictionary in Python

python dictionary get values

When I first started working with Python dictionaries more than a decade ago, I often found myself needing to extract just the values. Sometimes I wanted to analyze customer data stored in a dictionary. Other times, I needed to quickly convert values into a list for further processing. Over the years, I’ve discovered multiple ways … Read more >>

How to Get File Extension in Python?

python get file type

When I was working on a project, I had to process hundreds of files stored in a shared folder. The challenge was simple: I needed to identify file extensions before performing any operation. At first, I thought Python would have an easy function for it. However, I soon realized that there are multiple ways to … Read more >>

Get Absolute Value in Python Without Using abs() Function

python absolute value

Over my 10+ years of working with Python, I’ve often come across situations where I needed to calculate the absolute value of a number but couldn’t use the built-in abs() function. At first, this might sound unusual; after all, abs() is quick and reliable. But in real-world projects, especially coding interviews, algorithm challenges, or restricted … Read more >>

Get the First Key in a Python Dictionary

python get first element of dict

Recently, I was working on a project where I had to quickly retrieve the first key from a Python dictionary. At first, it sounded simple, but when I dug deeper, I realized that dictionaries don’t behave exactly like Python lists. The challenge was that dictionaries are unordered collections in older versions of Python. But starting … Read more >>

Check if a Python Dictionary Contains a Key or Value

python dictionary contains

I was working on a project where I had to validate data stored in a Python dictionary. The challenge was simple: I needed to check if a dictionary contained specific keys or values. At first, I thought there might be a built-in function like dict.contains(). But soon, I realized Python doesn’t have such a function. … Read more >>

Matplotlib subplots_adjust for Bottom and Right Margins

Matplotlib subplots_adjust for Bottom and Right Margins

When I was working on a data visualization project for a client in the USA, I had to prepare multiple charts for a business dashboard. The issue was that the axis labels and titles were getting cut off because the margins at the bottom and right side were too tight. That’s where the subplots_adjust() function … Read more >>

How to Create 3D Subplots in Matplotlib (Python)

Matplotlib 3D subplots: a 2x2 grid with a surface, a wireframe, a 3D scatter plot and a 3D helix line

To create 3D subplots in Matplotlib, pass projection=”3d” to the subplot you want in 3D: fig.add_subplot(1, 2, 2, projection=”3d”), or make every subplot 3D with plt.subplots(2, 2, subplot_kw={“projection”: “3d”}). You can mix 2D and 3D subplots in one figure and use any 3D plot type (surface, wireframe, scatter, line) in each. This guide shows each … Read more >>

Python Matplotlib Add a Colorbar to Each Subplot

Python Matplotlib Add Colorbar to Each Subplot

As a developer, I was working on a Python project where I had to visualize multiple datasets side by side using subplots. Each subplot had its own scale and color mapping. The challenge I faced was how to add a separate colorbar to each subplot in Matplotlib. At first, I tried to use a single … Read more >>