Articles on Trending Technologies

Technical articles with clear explanations and examples

Check if array can be divided into two sub-arrays such that their absolute difference is Ks in Python

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 171 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
Yaswanth Varma
Updated on 28-Aug-2025 555 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

How to delete consonants from a string in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 28-Aug-2025 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

How to convert date to datetime in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 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

How to perform arithmetic operations on a date in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 28-Aug-2025 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

How to get min, seconds and milliseconds from datetime.now() in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 21K+ 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

How to subtract Python timedelta from date in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 28-Aug-2025 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

How to write a regular expression to match either a or b in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 28-Aug-2025 6K+ Views

In Python regular expressions, one of the common tasks is matching either one character or another. we can done this easily by using the re module along with the pipe symbol |, which acts as an OR operator. In this article, we’ll explore how to match either 'a' or 'b' in a string using regex. The following are the various methods included. Using re.search() with the | symbol The re.search() combined with the | (OR) symbol allows us to search for multiple patterns within a single string. It returns a match object if any of the patterns are found. The ...

Read More

Why do I get different timestamps in python on different machines?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 28-Aug-2025 341 Views

A timestamp represents a specific point in time as a numerical value. It typically measures the number of seconds that have elapsed since the Unix epoch, which is January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC). The main reasons behind timestamp variations on different machines include differences in time zones, system clocks, locale settings, and the use of UTC and local time (such as IST, PST, or CET). In this article, we will explore timestamp differences across different machines by considering the following key factors. Different System Time Zones If each system were set to different time zones like ...

Read More

How to convert a datetime string to millisecond UNIX time stamp?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 28-Aug-2025 2K+ Views

A millisecond UNIX timestamp is a number that shows how many milliseconds have elapsed since the beginning of the Unix epoch, which is January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC) up to the current moment or specified date and time. Instead of counting time in days, hours, or minutes, it counts in milliseconds (1 second = 1000 milliseconds). In Python, the common way to convert a Datetime object to a milliseconds timestamp involves using the strptime() function (to parse a string into a Datetime object), then converting this datetime object into a UNIX timestamp by using the timestamp() method, ...

Read More
Showing 81–90 of 61,248 articles
« Prev 1 7 8 9 10 11 6125 Next »
Advertisements