Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Set update() in Python to do union of n arrays
In this tutorial, we will use the set.update() method to find the union of multiple arrays. This method efficiently combines arrays while automatically removing duplicates, returning a one-dimensional array with all unique values. What is set.update()? The update() method adds elements from an iterable (like a list or array) to an existing set. It automatically handles duplicates by keeping only unique values. Syntax set.update(iterable) Example Let's see how to union multiple arrays using set.update() ? # initializing the arrays arrays = [[1, 2, 3, 4, 5], [6, 7, 8, 1, ...
Read MoreSend SMS updates to mobile phone using python
In this tutorial, we are going to learn how to send SMS messages in Python using the Twilio API service. Twilio provides a simple and reliable way to send SMS messages programmatically. Setting Up Twilio Account First, go to Twilio and create an account. You will get a free trial account with some credits to test SMS functionality. Complete the account setup and verify your phone number. Installation Install the twilio module using pip ? pip install twilio Getting Twilio Credentials From your Twilio Console Dashboard, you need to collect ? ...
Read Moreself in Python class
In this tutorial, we are going to learn about self in Python classes. The self parameter is a reference to the current instance of a class and is used to access variables and methods belonging to that instance. Note − self is not a keyword in Python. What is self? We use self in classes to represent the instance of an object. We can create multiple instances of a class and each instance will have different values. The self parameter helps us access those property values within the class instance. Basic Example Let's see how ...
Read MoreCalculate difference between adjacent elements in given list using Python
Calculating the difference between adjacent elements in a list is a common task in data analysis. Python provides several efficient approaches to solve this problem using list comprehension, loops, or built-in functions. Problem Definition Given a list, we need to calculate the difference between each adjacent pair of elements (next element minus current element). The result will have one fewer element than the original list. Example Scenario Input: [10, 15, 12, 18] Output: [5, -3, 6] Explanation: 15 - 10 = 5 12 - 15 = -3 18 - 12 = 6 ...
Read MoreAlternate element summation in list (Python)
The given task is to perform an alternate summation on a Python List. For example, adding the elements at even indices (0, 2, 4) or odd indices (1, 3, 5), depending on the requirement. This means we need to add every other element from the given list. Let us see an input scenario − Scenario Input: [11, 22, 33, 44, 55] Output: 99 Explanation: Here, we are going to add the elements at the even indices by using the slicing [::2]. Using sum() with List Slicing The alternate element summation in a list can ...
Read MorePython Grouped Flattening of list
In this tutorial, we will write a program that performs grouped flattening of a list containing sub-lists. This technique groups consecutive sublists together and flattens them into single lists, creating chunks of a specified size. Problem Statement Given a list of sublists and a number, we need to group the sublists in chunks of the given number and flatten each group into a single list. Input lists = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] number = 2 Expected Output [[1, 2, 3, 4], [5, 6, 7, 8], ...
Read MorePython How to copy a nested list
In this tutorial, we are going to see different ways to copy a nested list in Python. A nested list is a list that contains other lists as elements. When copying nested lists, we need to create independent copies of both the outer list and inner lists to avoid unwanted modifications. Let's explore three effective methods to achieve this ? Using Nested Loops The most straightforward approach uses nested loops to manually copy each element ? # initializing a list nested_list = [[1, 2], [3, 4], [5, 6, 7]] # empty list copy_list = ...
Read MorePython Indexing a sublist
In this tutorial, we will learn how to find the index of a sublist that contains a specific element. This is useful when working with nested lists where you need to locate which sublist contains your target element. Problem Statement Given a nested list, we need to find the index of the sublist that contains a specific element ? nested_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]] Expected output for elements 7, 5, and 3 ? Index of 7: 2 Index of 5: 1 Index of 3: 0 ...
Read MorePython Index specific cyclic iteration in list
In this tutorial, we will learn how to cyclically iterate through a list starting from a specific index. Cyclic iteration means when we reach the end of the list, we continue from the beginning until all elements are visited. Algorithm Steps Initialize the list and starting index Find the length of the list using len() Iterate over the list using the length Find the current element index using (start_index + i) % length Print the element at that index Example Let's implement cyclic iteration starting from index 5 ? # initializing the ...
Read MorePython Grouping similar substrings in list
In this tutorial, we are going to write a program that groups similar substrings from a list. We'll use Python's itertools.groupby() method to group strings that share a common prefix. Problem Understanding Given a list of strings with a common pattern (prefix-suffix), we want to group them by their prefix. Input strings = ['tutorials-python', 'tutorials-c', 'tutorials-java', 'tutorials-javascript', 'python-1', 'python-2', 'javascript-1'] Expected Output [['tutorials-python', 'tutorials-c', 'tutorials-java', 'tutorials-javascript'], ['python-1', 'python-2'], ['javascript-1']] Solution Using itertools.groupby() The itertools.groupby() method groups consecutive elements that have the same key. We'll use a lambda function ...
Read More