Sort Words in Lexicographical Order in Python

Yaswanth Varma
Updated on 28-Aug-2025 12:45:34

3K+ Views

Lexicographical order is similar way the words are arranged in a dictionary. In this article, we are going to learn how to sort the words in lexicographical order, which means arranging them in alphabetical order (A-Z). Python provides built-in methods like split() and sorted() to perform this operation. Using Python split() Method The Python split() method is used to split a string by using the specified separator. This separator is a delimiter string and can be a comma, a full stop, or any other character to split a string. Syntax Following is the syntax of Python str.split() method ... Read More

Check If Array Can Be Divided Into Two Sub-Arrays With Absolute Difference in Python

Yaswanth Varma
Updated on 28-Aug-2025 12:40:37

117 Views

In this article we are going to check whether the given array can be divided into two sub-array in such a way that the absolute difference between the sums of these two sub-array is equal to the given value k. The absolute difference is nothing but the non-negative gap between two numbers, calculated as abs(sum1-sum2). In this task the split must produce two non-empty sub-array i.e. at least one element should be present in each part. Example scenarios Following are the example scenarios: Scenario 1 Input: array = [3, 1, 4, 2, 2], K = 4 ... Read More

Check If Array Contains Contiguous Integers with Duplicates Allowed in Python

Yaswanth Varma
Updated on 28-Aug-2025 12:37:04

473 Views

Check for Contiguous Integers in an Array A sequence of numbers is said to be contiguous if the numbers can be arranged in such a way that each number follows the previous one without any gaps. For example,  [11, 12, 13, 14] is a contiguous sequence because there are no missing numbers between the smallest and largest values. In this article, we need to check if an array contains such contiguous integers, even when the duplicates are present. For instance, [11, 12, 13, 13, 14] should still be considered contiguous because the unique numbers are [11, 12, 13, ... Read More

Delete Consonants from a String in Python

Yaswanth Varma
Updated on 28-Aug-2025 12:32:39

1K+ Views

The consonants are the alphabetic characters that is not a vowel (a, e, i, o, u). In Python, String manipulation is the common task, In this article we will explore how to delete consonants from a string using different approaches, including loops, list comprehensions and regular expression. Using Loop In this approach, we are going to declare the variable assignment with vowels in both upper and lower case and then looping through each character in the string. If the character is vowel or a non-alphabet character we will retrieve them and add to result. Example Let's ... Read More

Get Current Time in Milliseconds in Python

Pranav Indukuri
Updated on 28-Aug-2025 12:23:48

82K+ Views

We can retrieve the current time in milliseconds using different Python built-in modules like time, datetime, and calendar. These modules provide functions to work with time and dates. Each method gives us the time in a different format, but with a little calculation, we can convert it to milliseconds. The following are several methods used to achieve this. Using time.time() Method Using the datetime Module Using calendar.timegm() with datetime Using time.time() Method The time module in Python provides various methods and functions related to time. Here ... Read More

Convert Date to Datetime in Python

Pranav Indukuri
Updated on 28-Aug-2025 12:23:06

41K+ Views

In this article, we will discuss how to convert a date to a datetime object in Python. We use the combine() method from the Date & Time module to combine a date object and a time object into a single datetime object. While the date object represents only the calendar date (year, month, day), sometimes we need the full datetime object that includes time (hour, minute, second) as well. Following are the several ways to achieve this. The syntax of the combine() method is as follows. datetime.combine(date, time) Converting a date object to a datetime Object Using the combine() Method The ... Read More

Perform Arithmetic Operations on a Date in Python

Vikram Chiluka
Updated on 28-Aug-2025 12:21:12

8K+ Views

Performing arithmetic operations on dates allows us to calculate differences between dates, add or subtract time intervals, or compare one date with another using the datetime module in Python. This article will discuss how to perform several arithmetic operations using the datetime module in Python. Adding and Subtracting Days Using timedelta In the Python datetime module, timedelta is a class that represents the difference or duration between two dates or times. We can use timedelta objects to perform date arithmetic, such as adding or subtracting a certain number of days, weeks, hours, minutes, etc. To add or subtract days, we ... Read More

Get Minutes, Seconds and Milliseconds from Datetime Now in Python

Pranav Indukuri
Updated on 28-Aug-2025 12:17:24

20K+ Views

Python's datetime module is used to extract various components of the current date and time, such as minutes, seconds, and even milliseconds. The datetime.now() method defined in the datetime module returns the current local date and time as a datetime object. This object allows us to access its individual components like minute, second, and millisecond. Using Attributes of datetime.now() to Extract Values Here we use the datetime.now() method to get the current minutes, seconds, and milliseconds. The now() function is defined under the datetime module. And retrieve the current minutes, seconds, and milliseconds by using .minute, .second, and .microsecond, respectively. ... Read More

Subtract Python Timedelta from Date

Rajendra Dharmkar
Updated on 28-Aug-2025 12:15:29

11K+ Views

The Python datetime module provides various ways for manipulating dates and times. One of its key features is the timedelta object, which represents duration and also the difference between two dates or times. Subtracting a specific amount of time from a date can be done using timedelta. For example, if we want to find the date a day before today, then we create a timedelta object with days=1 and then subtract it from the current date. Subtracting One Day from Today's Date Using timedelta The basic use case is subtracting a single day from today's date. This can be done ... Read More

Return Current CPU Time in Python

Pranav Indukuri
Updated on 28-Aug-2025 12:14:05

5K+ Views

In this article, we retrieve the current CPU time in Python using the time() method,  which is imported from the Python time module. The time module in Python provides various methods and functions related to time. Here we use the time.The time() method to get the current CPU time in seconds. The time is calculated since the epoch. This method returns a float value that represents the seconds since the epoch. Epoch is the starting point of time and is platform-dependent. The epoch is January 1, 1970, 00:00:00 (UTC) on Windows and most Unix systems, and leap seconds are not included in the ... Read More

Advertisements