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
Python Program to Implement Queue Data Structure using Linked List
A queue is a linear data structure that follows the First In First Out (FIFO) principle. When implementing a queue using a linked list, we need methods to add elements at the rear (enqueue) and remove elements from the front (dequeue). Queue Implementation Structure Our queue implementation consists of two classes ? class Node: def __init__(self, data): self.data = data self.next = None class Queue: def __init__(self): ...
Read MorePython Program to Implement a Stack using Linked List
When implementing a stack data structure using a linked list, we need methods to add (push) elements to the top and remove (pop) elements from the top. In a stack, the last element added is the first one to be removed (LIFO - Last In First Out). Node Class First, we create a Node class to represent individual elements in the linked list ? class Node: def __init__(self, data): self.data = data self.next = None ...
Read MorePython Program to Print the Alternate Nodes in a Linked List using Recursion
When working with linked lists, we often need to print alternate nodes (1st, 3rd, 5th, etc.). This can be achieved using recursion by skipping one node at each recursive call. We'll create a linked list class with methods to add elements and a recursive function to print alternate nodes. Node Class First, let's define a simple Node class to represent individual elements in our linked list ? class Node: def __init__(self, data): self.data = data self.next ...
Read MorePython Program to Find the Length of the Linked List without using Recursion
When it is required to find the length of a linked list without using recursion, we define methods to add elements to the linked list and calculate its length using iterative approach. This approach uses a simple loop to traverse through all nodes and count them. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): ...
Read MorePython Program to Display the Nodes of a Linked List in Reverse without using Recursion
When it is required to display the nodes of a linked list in reverse without using the method of recursion, we can use an iterative approach. This involves finding the last unprinted node in each iteration and displaying it. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): ...
Read MorePython Program to Display all the Nodes in a Linked List using Recursion
When it is required to display the elements/nodes in a linked list using recursion, we need a method to add values to the linked list and a recursive helper method that calls itself repeatedly to print the values. The recursive approach provides an elegant way to traverse the entire linked list. Below is a demonstration for the same − Node and LinkedList Classes First, we define the basic structure of our linked list ? class Node: def __init__(self, data): self.data = data ...
Read MorePython Program to Search for an Element in the Linked List without using Recursion
Searching for an element in a linked list is a fundamental operation. This article demonstrates how to implement a non-recursive search algorithm that finds an element and returns its index position in a linked list. Node Class Definition First, we create a Node class to represent individual elements in the linked list ? class Node: def __init__(self, data): self.data = data self.next = None Linked List Implementation The linked list class contains methods ...
Read MorePython Program to Create a Linked List & Display the Elements in the List
A linked list is a linear data structure where elements are stored in nodes, and each node contains data and a reference to the next node. Unlike arrays, linked list elements are not stored in contiguous memory locations. Below is a demonstration of creating a linked list and displaying its elements ? Node Class Structure First, we create a Node class to represent individual elements ? class Node: def __init__(self, data): self.data = data self.next ...
Read MoreAppend Dictionary Keys and Values (In order ) in dictionary using Python
When you need to append dictionary keys and values in order, Python provides several approaches. The most straightforward method uses the list() function with .keys() and .values() methods to extract and concatenate them. Basic Approach Using list() and Concatenation This method converts dictionary keys and values to lists, then concatenates them ? my_dict = {"January": 1, "Feb": 2, "March": 3, "April": 4, "May": 5, "June": 6} print("The dictionary is:") print(my_dict) my_result = list(my_dict.keys()) + list(my_dict.values()) print("The ordered key and value are:") print(my_result) The dictionary is: {'January': 1, 'Feb': 2, 'March': ...
Read MoreConvert key-values list to flat dictionary in Python
When working with dictionaries that contain lists as values, you may need to convert them into a flat dictionary where elements from the lists become key-value pairs. Python provides several approaches to achieve this transformation. Understanding the Problem A key-values list dictionary has keys mapped to lists of values. Converting to a flat dictionary means pairing corresponding elements from these lists into key-value pairs. Using zip() Method The most common approach uses zip() to pair corresponding elements from two lists ? my_dict = {'month_num': [1, 2, 3, 4, 5, 6], 'name_of_month': ['Jan', 'Feb', 'March', ...
Read More