Python Articles - Page 528 of 829

Python Program to Print an Identity Matrix

AmitDiwan
Updated on 11-Mar-2021 12:35:14

869 Views

When it is required to print an identity matrix, nested loops can be used.Below is a demonstration for the same −Example Live Demon = 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):          print("1", sep=" ", end=" ")       else:          print("0", sep=" ", end=" ")    print()OutputThe value of n has been initialized to 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1ExplanationThe value of ‘n’ ... Read More

Python program to search an element in a doubly linked list

AmitDiwan
Updated on 11-Mar-2021 12:33:43

605 Views

When it is required to search for an element 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 of the linked list, and the access to the previous node of the linked list.Another class needs to be created that would have an initialization function, and the head of the node would be initialized to ‘None’ inside this.Multiple methods are defined by the user to add node to the linked list, to display the nodes it and ... Read More

Python program to rotate doubly linked list by N nodes

AmitDiwan
Updated on 11-Mar-2021 12:30:33

303 Views

When it is required to rotate a doubly linked list by a specific number of nodes, 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 −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = ... Read More

Python program to remove duplicate elements from a Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:28:04

316 Views

When it is required to remove the 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 of the linked list, and the access to the previous node of the linked list.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = None   ... Read More

Python program to insert a new node at the middle of the Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:23:46

453 Views

When it is required to insert a new node in the middle 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 −Example Live Democlass Node:    def __init__(self, my_data):       self.previous = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head ... Read More

Python program to insert a new node at the end of the Doubly Linked List

AmitDiwan
Updated on 11-Mar-2021 12:19:49

583 Views

When it is required to insert a new node at the end 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 −Example Live Democlass Node:    def __init__(self, my_data):       self.prev = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head ... Read More

Python program to insert a new node at the beginning of the Doubly Linked list

AmitDiwan
Updated on 11-Mar-2021 12:16:22

444 Views

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 −Example Live Democlass Node:    def __init__(self, my_data):       self.prev = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head ... Read More

Python program to find the maximum and minimum value node from a doubly linked list

AmitDiwan
Updated on 11-Mar-2021 12:13:41

486 Views

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.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, my_data):       self.prev = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = ... Read More

Python program to delete a new node from the middle of the doubly linked list

AmitDiwan
Updated on 11-Mar-2021 12:09:53

371 Views

When it is required to delete a node from the middle 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.Another class needs to be created that would have an initialization function, and the head of the node would be initialized to ‘None’ inside this.Multiple methods are defined by the user to add node to the linked list, to display the nodes ... Read More

Python program to delete a new node from the end of the doubly linked list

AmitDiwan
Updated on 11-Mar-2021 12:05:57

561 Views

When it is required to delete a node from the end 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 −Example Live Democlass Node:    def __init__(self, my_data):       self.prev = None       self.data = my_data       self.next = None class double_list:    def __init__(self):       self.head = ... Read More

Advertisements