Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 14 of 26

string.whitespace in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 451 Views

In this tutorial, we are going to learn about the string.whitespace.The string whitespace is pre-defined in the string module of Python3. If contains space, tab, linefeed, return, formfeed, and vertical tab.Example# importing the string module import string # printing a string print("Hello") # whitespace printing print(string.whitespace) # printing a string print('tutorialspoint')OutputIf you run the above code, then you will get the following result.Hello tutorialspointConclusionIf you have any doubts in the tutorial, mention them in the comment section.

Read More

struct module in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 4K+ Views

In this tutorial, we are going to learn about the struct module. Let's dive into the tutorial.The module struct is used to convert the native data types of Python into string of bytes and vice versa. We don't have to install it. It's a built-in module available in Python3.The struct module is related to the C languages. We have to know the notations used in C to represent various data type to work with struct module. Let's see some of them.Data TypeFormat CharacterinticharcstringsfloatfLet's see how to convert the Python data types into bytes.struct.pack()The method struct.pack() is used to convert the ...

Read More

Program for longest common directory path in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 511 Views

In this tutorial, we are going to write a program that finds the longest common path from the given list of paths. Let's see an example to understand the problem statement more clearly.Inputpaths = ['home/tutorialspoint/python', 'home/tutorialspoint/c', 'home/tutorialspoint/javascript', 'home/tutorialspoint/react', 'home/tutorialspoint/django']/home/tutorialspoint/We can solve the problem using os module very easily. Let's see the steps to solve theImport the os module.Initialize the list of paths to find the longest common path.Find the common prefix of all paths using os.path.commonprefix(paths) and store it in variable.And extract the directory from the common prefix using os.path.dirname(common_prefix).Example# importing the os module import os # initializing the paths ...

Read More

Sum of list (with string types) in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we are going to write a program that adds all numbers from the list. List may contain numbers in string or integer format. See the example.Inputrandom_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020]Output4051Follow the below steps to write the program.Initialize the list.3Initialize a variable total with 0.Iterate over the list.If the element is int, then add it to the total by checking two conditions.The element will be int -> Check type.The element will be a number in string format -> Check using isdigit() method.Print the totalExample# initialzing the list random_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020] ...

Read More

Program to check congruency of two triangles in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 384 Views

In this tutorial, we are going to check the congruency of two triangles. We are going to check SSS, SAS, and AAA. The similarity of the triangles is proved based on those criteria.We have to check different conditions based on the theorem. Check them in the code below.Exampledef side_side_side(sides_one, sides_two):    # sorting same pace    sides_one.sort()    sides_two.sort()    # checking the conditions    if sides_one[0] / sides_two[0] == sides_one[1] / sides_two[1] \       and sides_one[1] / sides_two[1] == sides_one[2] / sides_two[2] \       and sides_one[2] / sides_two[2] == sides_one[0] / sides_two[0]:       ...

Read More

Python Getting sublist element till N

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 326 Views

In this tutorial, we are going to write a program that returns a sublist element till nth sublist in a list. Let's say we have the following list with 5 sublists.[['Python', 'Java'], ['C', 'Pascal'], ['Javascript', 'PHP'], ['C#', 'C++'], ['React', 'Angular']] Now, we have to get the first element from the first three sublists. We can get the elements different approaches. Let's see some of them.LoopsMore generic and first thought of the most of programmers is to use loops. Let's see the code using loops.Example# initializing the list and N random_list = [['Python', 'Java'], ['C', 'Pascal'], ['Javascript', 'PHP'], ['C# C++'], ['React', ...

Read More

Python Group Anagrams from given list

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 4K+ Views

In this tutorial, we are going to write a program that groups all anagrams in a list. First, let's see what are anagrams.Any two strings that have the same character in a different order are known as anagrams.Before diving into the solution, let's see an example.Input['cat', 'dog', 'fired', 'god', 'pat', 'tap', 'fried', 'tac']Output[['cat', 'tac'], ['dog', 'god'], ['fried', 'fired'], ['pat', 'tap']]We will breakdown the problem into two pieces. First, we will write a function that checks two strings are anagrams or not. Follow the below steps to write code to check anagrams.Initialize the strings.Sort both the strings.If both sorted strings are ...

Read More

Swap two variables in one line in C/C++, Python, PHP and Java

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 658 Views

In this tutorial, we are going to learn how to swap two variables in different languages. Swapping means interchanging the values of two variables. Let's see an example.Inputa = 3 b = 5Outputa = 5 b = 3Let's see one by one.PythonWe can swap the variable with one line of code in Python. Let's see the code.Example# initializing the variables a, b = 3, 5 # printing before swaping print("Before swapping:-", a, b) # swapping a, b = b, a # printing after swapping print("After swapping:-", a, b)OutputIf you run the above code, then you will get the following result.Before ...

Read More

Python Group elements at same indices in a multi-list

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 730 Views

In this tutorial, we are going to write a program that combines elements of the same indices different lists into a single list. And there is one constraint here. All the lists must be of the same length. Let's see an example to understand it more clearly.Input[[1, 2, 3], [4, 5, 6], [7, 8, 9]]Output[[1, 4, 7], [2, 5, 8], [3, 6, 9]]We can solve it in different ways. Let's see how to solve with normal loops.Initialize the list with lists.Initialize an empty list.Initialize a variable index to 0.Iterate over the sub list length timesAppend an empty list to the ...

Read More

The most occurring number in a string using Regex in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 277 Views

In this tutorial, we are going to write a regex that finds the most occurring number in the string. We will check the regex in Python.Follow the below steps to write the program.Import the re and collections modules.Initialize the string with numbers.4Find all the numbers using regex and store them in the array.Find the most occurring number using Counter from collections module.Example# importing the modules import re import collections # initializing the string string = '1222tutorials321232point3442' # regex to find all the numbers regex = r'[0-9]' # getting all the numbers from the string numbers = re.findall(regex, string) # counter ...

Read More
Showing 131–140 of 259 articles
« Prev 1 12 13 14 15 16 26 Next »
Advertisements