Gireesha Devara

Gireesha Devara

174 Articles Published

Articles by Gireesha Devara

Page 4 of 18

Convert \"unknown format\" strings to datetime objects in Python

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 2K+ Views

Dates can be in many formats like "2009/05/13 19:19:30", "May 13 2009 07:19PM", and "2009-05-13 19:19". Python provides several approaches to convert these unknown format strings into datetime objects using the datetime and dateutil modules. A Python datetime object contains complete information about date and time including year, month, day, hours, minutes, seconds, and time zones. This article shows how to convert unknown format date strings to datetime objects. Input-Output Example Here's what we want to achieve ? Input string (unknown format): 20050607T090650 Output Datetime object: 2005-06-07 09:06:50 Data type: Using datetime.strptime() ...

Read More

Python Program to insert multiple elements into the array from the specified index

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 2K+ Views

An array is a collection of homogeneous data elements stored in an organized way. Each data element in the array is identified by an index value. In Python, we can insert multiple elements at a specific index position using various approaches. Arrays in Python Python does not have a native array data structure, so we use the list data structure as an alternative ? # Python list example my_list = [10, 4, 11, 76, 99] print(my_list) [10, 4, 11, 76, 99] We can also use the NumPy module to work with ...

Read More

Python Program to find the distinct elements from two arrays

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

In programming, an array is a data structure used to store a collection of homogeneous data elements. Each element is identified by a key or index value. In Python, we use lists to represent arrays. Finding distinct elements from two arrays means identifying unique elements that exist in one array but not in the other − this is also known as the symmetric difference. Input Output Scenarios Let's look at example inputs and expected outputs ? Input arrays: A = [1, 2, 3, 4, 5] B = [5, 2, 6, 3, 9] Output array: [1, ...

Read More

Python Program to get the first given number of items from the array

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 275 Views

An array is a data structure of a set of items with the same data type, and each element is identified by an index. In Python, we can get the first few items from an array using slicing syntax array[:n]. Arrays in Python Python does not have its own data structure to represent an array. However, we can use the list data structure as an alternative to the arrays. Here we will use list as an array − numbers = [10, 4, 11, 76, 99] print(numbers) [10, 4, 11, 76, 99] ...

Read More

Python Program to get the last item from the array

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 323 Views

An array is a data structure used to store a collection of homogeneous data elements. Each element in the array is identified by an index value or key. Arrays in Python Python doesn't have a built-in data structure to represent arrays, but it has a built-in array module for working with arrays. We can also use the NumPy package. An array defined by the array module is − import array arr = array.array('i', [1, 2, 3, 4]) print(arr) array('i', [1, 2, 3, 4]) A NumPy array defined by the NumPy ...

Read More

Python Program to get the subarray from an array using a specified range of indices

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 15K+ Views

An array is a homogeneous data structure used to store elements of the same data type. Each element is identified by a key or index value. Python provides several ways to extract subarrays from arrays using specified index ranges. What is a Subarray? A subarray is a continuous portion of elements from an array. For example, if we have an array: numbers = [9, 3, 1, 6, 9] print("Original array:", numbers) Original array: [9, 3, 1, 6, 9] The possible subarrays include: [9, 3] [9, 3, 1] [3, ...

Read More

Python Program to push an array into another array

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

In programming, an array is a data structure used to store a collection of homogeneous data elements. Each element is identified by an index value. Python doesn't have a specific array data type, so we use lists as arrays. Arrays in Python Here's how we represent a list as an array ? numbers = [1, 4, 6, 5, 3] print(numbers) [1, 4, 6, 5, 3] Python indexing starts from 0, so elements are accessed using index values 0, 1, 2, 3, 4. Pushing an array into another array means inserting ...

Read More

Python Program to convert an array into a string and join elements with a specified character

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 436 Views

An array is a data structure consisting of a collection of elements of the same data type, where each element is identified by an index. In Python, we use lists to represent arrays and can convert them to strings with custom separators. Arrays in Python Python uses the list data structure to represent arrays. Here's an example of a list representing an array − numbers = [10, 4, 11, 76, 99] print(numbers) [10, 4, 11, 76, 99] Input Output Scenarios Let's see how array elements can be joined with specified ...

Read More

Python Program To Determine If a Given Matrix is a Sparse Matrix

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 765 Views

A matrix is a rectangular array of numbers arranged in rows and columns. A sparse matrix is one that contains significantly more zero elements than non-zero elements − typically when more than half of the elements are zero. What is a Sparse Matrix? Consider this example matrix ? [0, 0, 3, 0, 0] [0, 1, 0, 0, 6] [1, 0, 0, 9, 0] [0, 0, 2, 0, 0] This 4×5 matrix has 20 total elements but only 6 non-zero values. Since 14 out of 20 elements are zero (70%), this qualifies as a sparse ...

Read More

Python Program to Display Upper Triangular Matrix

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 3K+ Views

A matrix is a two-dimensional array of numbers arranged in rows and columns. A square matrix (whose rows and columns have the same number of elements) has two diagonals. One is the primary diagonal − located from the top left corner to the bottom right corner. The second is the secondary diagonal − located from the top right to the bottom left corner. For a square matrix, if all the elements below the primary diagonal are zero, then it is called the Upper Triangular Matrix. # Example of upper triangular matrix matrix = [[1, 3, 4], ...

Read More
Showing 31–40 of 174 articles
« Prev 1 2 3 4 5 6 18 Next »
Advertisements