How I Check If a List Contains a Sublist in Python

python find sublist in list

Recently, I was working on a data-cleaning project where I had to verify if a smaller list of values existed inside a larger dataset. At first, I thought Python might have a direct built-in method for this. But just like in Excel, where you don’t always get a direct option (for example, filtering strikethrough text), … 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 >>

Write a Program to Find a Perfect Number in Python

perfect number in python

Recently, I was working on a small project where I needed to check if a number was a perfect number. At first, I thought Python might have a built-in function for this. But just like Excel doesn’t have a direct way to filter strikethrough cells, Python doesn’t come with a ready-made tool for perfect numbers. … Read more >>

Python Program to Find the Area of a Rectangle

Python program to find the area of a rectangle: the Command Prompt showing the length, width, area and perimeter printed

The area of a rectangle in Python is length * width. That’s the whole calculation, and here it is as a program you can run: What people usually need on top of that is the version that asks the user for the numbers, and one that survives being given nonsense. Both are below. Each program … Read more >>

How to Convert a Pandas DataFrame to a TensorFlow Tensor

dataframe to tensor

This TensorFlow tutorial will teach you how to convert pandas dataframe to tensor dataset. I created a model in TensorFlow to predict housing prices. I collected data related to houses, such as square footage, location, and number of bedrooms, and then organized the collected data into a Pandas dataframe for preprocessing. After preprocessing, I had … Read more >>

How to Convert a List to a Tensor in TensorFlow

tf convert to tensor

When I first started working with TensorFlow, one of the things that confused me was how to take a regular Python list and turn it into a tensor. It sounds simple, right? But when you’re dealing with machine learning models, you often get data in lists or arrays, and you need to convert them into … Read more >>

Get the First N Characters of a String in Python

Python get the first n characters of a string: the Command Prompt showing slice syntax in use

To get the first n characters of a string in Python, slice from the start: The useful part is what it doesn’t do. Asking for more characters than the string has returns the whole string rather than raising an error. All output below comes from real runs on Python 3.12.5. Getting the first n characters … Read more >>

Lambda in List Comprehension in Python

python list comprehension lambda

I was working on a data-cleaning task where I had to transform and filter a list of U.S. city names. I wanted a quick way to apply conditions and transformations without writing long functions. That’s when lambda with list comprehension came in handy. This combination gave me cleaner, more Pythonic code. In this tutorial, I’ll … Read more >>