Hafeezul Kareem

Hafeezul Kareem

258 Articles Published

Articles by Hafeezul Kareem

Page 5 of 26

Program to check congruency of two triangles in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 428 Views

In geometry, two triangles are congruent if they have the same shape and size. We can check triangle congruency using three main criteria: SSS (Side-Side-Side), SAS (Side-Angle-Side), and ASA (Angle-Side-Angle). Note that AAA (Angle-Angle-Angle) only proves similarity, not congruency. Let's implement functions to check each congruency condition ? SSS (Side-Side-Side) Congruency Two triangles are congruent if all three corresponding sides are equal ? def side_side_side_congruent(sides_one, sides_two): # Sort both lists to compare corresponding sides sides_one_sorted = sorted(sides_one) sides_two_sorted = sorted(sides_two) ...

Read More

Program for longest common directory path in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 551 Views

In this tutorial, we are going to write a program that finds the longest common directory path from a given list of paths. This is useful when working with file systems or organizing directory structures. Problem Statement Given a list of file paths, we need to find the longest directory path that is common to all of them ? paths = ['home/tutorialspoint/python', 'home/tutorialspoint/c', 'home/tutorialspoint/javascript', 'home/tutorialspoint/react', 'home/tutorialspoint/django'] Expected Output: home/tutorialspoint Using os.path.commonprefix() Python's os module provides os.path.commonprefix() to find the common prefix of multiple ...

Read More

Calculating Wind Chill Factor(WCF) or Wind Chill Index(WCI) in Python Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 627 Views

In this tutorial, we will learn how to calculate the Wind Chill Factor (WCF) or Wind Chill Index (WCI) in Python. The wind chill index measures how cold it feels when wind is factored in with the actual air temperature. Wind Chill Formula We use the following standard formula to calculate the Wind Chill Index ? Twc = 13.12 + 0.6215Ta − 11.37v0.16 + 0.3965Tav0.16 Where: Twc = Wind Chill Index (in degrees Celsius) Ta = Air Temperature (in degrees Celsius) v = Wind Speed (in kilometers per hour) Implementation Steps Follow ...

Read More

Lambda expression in Python Program to rearrange positive and negative numbers

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 885 Views

In this tutorial, we will write an anonymous function using lambda to rearrange positive and negative numbers in a list. The goal is to place all negative numbers first, followed by all positive numbers. Algorithm Let's see how to solve the problem step by step ? 1. Initialize a list with negative and positive numbers. 2. Write a lambda expression that takes a list as an argument. 2.1. Iterate over the list and get negative numbers 2.2. Same for positive numbers 2.3. Combine both using concatenation operator. ...

Read More

Python Dictionary Comprehension

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 536 Views

In this tutorial, we are going to learn how to use dictionary comprehensions in Python. If you are already familiar with list comprehension, then it won't take much time to learn dictionary comprehensions. Dictionary comprehension provides a concise way to create dictionaries using a single line of code. We need key-value pairs to create a dictionary. The general syntax of dictionary comprehension is: {key: value for item in iterable} Basic Dictionary Comprehension Let's see how to generate numbers as keys and their squares as values within the range of 10. Our result should look ...

Read More

Program to print its script name as output in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 1K+ Views

In this tutorial, we are going to write a program that prints the name of the Python script file. We can find the script name using the sys module. The sys module stores all the command line arguments of the python command in the sys.argv list. The first element in the list is the script name. We can extract it from that list. Python makes it easy. Getting Script Name Only To print just the script filename without the full path ? import sys import os # Get just the filename script_name = os.path.basename(sys.argv[0]) ...

Read More

Writing files in the background in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 640 Views

In this tutorial, we will learn about multi-threading in Python to perform multiple tasks simultaneously. Python's threading module allows us to write files in the background while executing other operations concurrently. We'll demonstrate this by writing data to a file in the background while calculating the sum of numbers in a list. Here are the key steps involved ? Import the threading module Create a class inheriting from threading.Thread Implement the file writing logic in the run() method Start the background ...

Read More

Sum 2D array in Python using map() function

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 5K+ Views

In this tutorial, we are going to find the sum of a 2D array using map() function in Python. The map() function takes two arguments: function and iterable. It applies the function to every element of the iterable and returns a map object. We can convert the map object into a list or other iterable. Let's see how to find the sum of a 2D array using the map function ? Steps to Sum a 2D Array Initialize the 2D array using nested lists. Pass the sum ...

Read More

Run Length Encoding in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 2K+ Views

Run-length encoding compresses a string by grouping consecutive identical characters and representing them as character + count. For example, "aaabbc" becomes "a3b2c1". However, the example above shows a different approach - counting total occurrences of each character rather than consecutive runs. Let's explore both approaches. Character Frequency Encoding This approach counts total occurrences of each character ? import collections def character_frequency_encoding(string): # Initialize ordered dictionary to maintain character order count_dict = collections.OrderedDict.fromkeys(string, 0) # Count occurrences of ...

Read More

Print a Calendar in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 13K+ Views

In this tutorial, we are going to learn how to print the calendar of month and year using the calendar module of Python. Python's built-in calendar module makes it straightforward to display formatted calendars. We only need the year and month numbers. Printing a Year Calendar To print a complete year calendar, follow these steps ? Import the calendar module Initialize the year number Use calendar.calendar(year) to generate the calendar Example # importing the calendar module import calendar # ...

Read More
Showing 41–50 of 258 articles
« Prev 1 3 4 5 6 7 26 Next »
Advertisements