How to Find an Element’s Index in a Python Array

Find an Element’s Index in a Python Array

I recently built a small HR leave tracker for a 10-person team in Austin, Texas. The team previously tracked leave requests in Excel, but they needed a simple Python app with a local SQLite database. While processing requests, I often needed to find an employee, leave type, or approval status inside an array. Finding the … Read more >>

Python Generating Nested Dictionary Key Error

python keyerror

Recently, I was working on a data analysis project involving customer sales data from different US states. I needed to create nested dictionaries to organize sales information by state, city, and product categories. The challenge I faced was the dreaded KeyError that kept popping up whenever I tried to generate nested dictionary structures. This error … Read more >>

Print String with Quotes in Python

how to print quotation marks in python

While I was helping a junior developer on my team who was struggling with printing strings that contained quotes in Python. At first glance, it looks simple. But when you try to print a sentence like He said, “Python is amazing!”, Python throws errors if you don’t format it correctly. I’ve been working with Python … Read more >>

How to Build Perceptron in Python?

Mathematical Model of Perceptron

If you are a deep learning or machine learning enthusiast, you must know how to build Perceptron in Python, which is the foundation of creating AI, machine learning models, etc. I will explain the perceptron in depth with an example. You will understand how the perceptron works: it takes the input, processes the input, and … Read more >>

Check if a Variable Is Not Null in Python

python not null

I’ve often needed to verify if a variable is not null before proceeding with operations. This check is fundamental when working with data, user inputs, or APIs because null values can cause your program to crash or behave unexpectedly. In Python, the concept of “null” is represented by the special value None. Knowing how to … Read more >>

How to Convert a Dictionary to a String in Python

Convert a dict to a string in Python: Command Prompt output comparing str() and json.dumps() for the same dictionary

To convert a dict to a string in Python, use json.dumps(d) when the text will be stored, sent to an API or read by another program, and str(d) for a quick, Python-style text you only want to print or log. For a custom format such as key=value pairs, join the items yourself. This guide compares … Read more >>

Python Program to Swap Two Elements in a List

Python program to swap two elements in a list

Recently, I was working on a data-cleaning project where I had to reorder elements in a customer list.The challenge was simple: swap two items in a Python list. At first, I thought there might be a single “built-in” function to do this. But as I explored, I realized there are multiple ways to swap elements … Read more >>

Call by Value vs Call by Reference in Python

python passing by reference

I was working with a team of data analysts in New York. We were optimizing some Python functions that handled large datasets. During the review, one of the junior developers asked me: “Does Python use call by value or call by reference?” This is a common question. I’ve been coding in Python for more than … Read more >>

How to Swap Two Numbers in Python (With and Without a Function)

Swap two numbers in Python: Command Prompt output of tuple unpacking, a temp variable, arithmetic and XOR swaps

To swap two numbers in Python, use tuple unpacking: a, b = b, a. It is one line, works for any type (integers, floats, strings, list items) and needs no temporary variable. This guide shows that and the classic alternatives (a temporary variable, arithmetic and XOR), explains how swapping works inside a function, and includes … Read more >>