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 by AmitDiwan
Page 142 of 840
Python program to sort a list of tuples by second Item
When it is required to sort a list of tuples based on the second item, the lambda function and sorted() method can be used. A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuples basically contains tuples enclosed in a list. Anonymous function is a function which is defined without a name. In general, functions in Python are defined using def keyword, but anonymous function is defined with the help of lambda keyword. It takes a single expression, but can take ...
Read MorePython Program to Print an Identity Matrix
An identity matrix is a square matrix where the diagonal elements are 1 and all other elements are 0. In Python, you can create an identity matrix using nested loops or the NumPy library. Using Nested Loops The basic approach uses two nested loops to check if the row index equals the column index ? n = 4 print("The value of n has been initialized to " + str(n)) for i in range(0, n): for j in range(0, n): if(i == j): ...
Read MorePython program to search an element in a doubly linked list
When searching for an element in a doubly linked list, we need to create a Node class with three attributes: the data, a pointer to the next node, and a pointer to the previous node. We also need a main class to manage the list operations including adding nodes, displaying nodes, and searching for specific elements. In a doubly linked list, each node has bidirectional pointers − one pointing to the next node and another to the previous node. This allows traversal in both directions, making it more flexible than a singly linked list. Node Class Structure ...
Read MorePython program to rotate doubly linked list by N nodes
When working with doubly linked lists, rotation involves moving the first N nodes from the beginning to the end of the list. This requires a Node class with three attributes: data, next pointer, and previous pointer for bidirectional traversal. Node Class Structure Each node contains data and pointers to both next and previous nodes ? class Node: def __init__(self, my_data): self.previous = None self.data = my_data self.next = ...
Read MorePython program to remove duplicate elements from a Doubly Linked List
When it is required to remove duplicate elements in a doubly linked list, a Node class needs to be created. In this class, there are three attributes: the data that is present in the node, the access to the next node, and the access to the previous node of the linked list. Below is a demonstration for the same − Node Class Structure The Node class represents each element in the doubly linked list − class Node: def __init__(self, my_data): self.previous = None ...
Read MorePython program to insert a new node at the middle of the Doubly Linked List
When you need to insert a new node in the middle of a doubly linked list, you create a Node class with three attributes: the data, access to the next node, and access to the previous node. This allows bidirectional traversal and insertion at any position. Node Class Structure The Node class defines the structure of each element in the doubly linked list ? class Node: def __init__(self, my_data): self.previous = None self.data = my_data ...
Read MorePython program to insert a new node at the end of the Doubly Linked List
When inserting a new node at the end of a doubly linked list, we need to create a Node class that contains data and references to both the previous and next nodes. The doubly linked list maintains pointers to both the head and tail for efficient insertion. Node Structure A doubly linked list node contains three components ? prev data next Previous Node Node Data Next Node ...
Read MorePython program to insert a new node at the beginning of the Doubly Linked list
When it is required to insert a new node at the beginning of a doubly linked list, a 'Node' class needs to be created. In this class, there are three attributes: the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list. Below is a demonstration for the same − Node Class Structure First, we define the Node class with three attributes ? class Node: def __init__(self, my_data): ...
Read MorePython program to find the maximum and minimum value node from a doubly linked list
When it is required to find the maximum and minimum values from a doubly linked list, a Node class needs to be created. In this class, there are three attributes: the data that is present in the node, the access to the next node of the linked list, and the access to the previous node of the linked list. A doubly linked list allows traversal in both directions, making it easy to find minimum and maximum values by iterating through all nodes once. Implementation Below is a complete implementation that creates a doubly linked list and finds ...
Read MorePython program to delete a new node from the middle of the doubly linked list
When it is required to delete a node from the middle of a doubly linked list, a Node class needs to be created with three attributes: the data, access to the next node, and access to the previous node. In a doubly linked list, each node has pointers to both the next and previous nodes, allowing bidirectional traversal. The middle node deletion requires finding the center position and updating the surrounding node pointers. Node Class Structure The Node class stores data and maintains references to adjacent nodes ? class Node: def ...
Read More