Programming Articles

Page 45 of 2547

Finding the largest file in a directory using Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 2K+ Views

Finding the largest file in a directory is a common task for disk space management, analyzing file distributions, or automating cleanup operations. Python's os module provides several approaches to accomplish this efficiently. Algorithm Import the os module Define a function called find_largest_file that takes a directory as input Initialize variables largest_file to None and largest_size to 0 Use os.walk() to traverse the directory tree recursively For each file, get the file size using os.path.getsize() Compare file size to current largest and update if necessary Return the path of the largest file Method 1: Using a ...

Read More

Finding Duplicate Files with Python

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 2K+ Views

Duplicate files consume unnecessary storage space on our computers. Finding and removing them manually can be time-consuming, but we can automate this process with Python using file hashing techniques. Required Modules We'll use Python's built-in os and hashlib modules, so no additional packages need to be installed ? import os import hashlib How It Works The algorithm works by: Creating a hashfile() function that generates a unique SHA-1 hash for each file Storing hash values in a dictionary as we scan through files When the same hash appears twice, we've found ...

Read More

Finding Difference between Images using PIL

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 4K+ Views

In image processing, finding the difference between two images is a crucial step in various applications. It is essential to understand the difference between the two images, which can help us in detecting changes, identifying objects, and other related applications. In this tutorial, we will explore how to find the difference between two images using the Python Imaging Library (PIL). Installation To use PIL, we need to install it using the pip package manager − pip install pillow Basic Syntax To find the difference between two images using PIL, we can use the ...

Read More

Python Program to Reverse Every Kth row in a Matrix

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 975 Views

In Python, a matrix is a two-dimensional array where all elements have the same data type. Reversing every Kth row means flipping the order of elements in rows at positions K, 2K, 3K, and so on. In this article, we will learn different methods to reverse every Kth row in a matrix using Python. Problem Overview Given a matrix and a value K, we need to reverse the elements in every Kth row. For example, if K=2, we reverse the 2nd, 4th, 6th rows, etc. Input matrix = [[7, 1, 4], [3, 10, 6], ...

Read More

Python Program to find tuple indices from other tuple list

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 389 Views

Finding tuple indices from another tuple list is a common task in Python data manipulation. We can use several approaches: dictionary lookup with enumerate(), list comprehension, and the index() method. An ordered and immutable group of objects is referred to as a tuple. Sequences are just what tuples and lists both are. Tuples and lists vary in that tuples cannot be altered, although lists may, and because tuples use parentheses while lists use square brackets. Problem Statement Given an input list containing tuples and another search tuple list, we need to find the indices of the search ...

Read More

Python Program to extract dictionaries with maximum number of keys

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 199 Views

Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn a python program to extract dictionaries with the maximum number of keys from a list of dictionaries. Problem Overview Given a list containing multiple dictionaries, we need to find and extract the dictionary(ies) that have the maximum number of keys. Example Consider the following input list ? inputList = ...

Read More

Python Program to extract Dictionaries with given Key from a list of dictionaries

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 241 Views

Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of a group of key-value pairs. Each key-value combination corresponds to a key and its corresponding value. In this article, we will learn how to extract dictionaries that contain a specific key from a list of dictionaries using three different approaches. Problem Example Let's understand the problem with an example ? # Input list of dictionaries input_list = [ {'hello': 3, 'tutorialspoint': 6}, {'python': 9}, ...

Read More

Python program to convert URL Parameters to Dictionary items

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 2K+ Views

Python's implementation of a data structure known more commonly as an associative array is a dictionary. A dictionary is made up of key-value pairs, where each key corresponds to its associated value. URL parameters (query strings) often need to be parsed into dictionaries for easier manipulation in web applications. This article demonstrates three different methods to convert URL parameters into Python dictionary items. Methods Overview The following approaches will be covered ? Using urllib.parse.parse_qs() function Using setdefault() and re.findall() functions Using split() function Example Input and Output For all methods, we'll use ...

Read More

Python program to check whether number formed by combining all elements of the array is palindrome

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 193 Views

In Python, an array (list) is a collection of comma-separated values enclosed in square brackets. Lists are flexible as their elements don't need to be of the same type. In this article, we will learn how to check whether a number formed by combining all elements of an array is a palindrome ? Methods Used The following are the various methods to accomplish this task ? Using map() & join() functions Using type casting & string concatenation Using str(), list(), extend(), join() and reverse() functions Example Scenario Consider an input list. We ...

Read More

Python Program to Set from dictionary values

Aditya Varma
Aditya Varma
Updated on 27-Mar-2026 2K+ Views

In Python, a dictionary is an implementation of a data structure known as an associative array. A dictionary is made up of key-value pairs, where each key maps to its corresponding value. In this article, we will learn how to extract unique values from a dictionary and convert them into a set, which automatically removes duplicates. Example Overview Let's start with an example to understand what we want to achieve ? # Input dictionary with duplicate values input_dict = {'hello': 5, 'tutorialspoint': 10, 'users': 15, 'python': 5} print("Input dictionary:", input_dict) print("Dictionary values:", list(input_dict.values())) # ...

Read More
Showing 441–450 of 25,469 articles
« Prev 1 43 44 45 46 47 2547 Next »
Advertisements