A linked list is a type of linear data structure individual items are not necessarily at contiguous locations. The individual items are called nodes and connected with each other using links.
We have created a Node class in which we have defined a __init__ function to initialize the node with the data passed as an argument and a reference with None because if we have only one node then there is nothing in its reference.
classNode:def__init__(self,data):self.data=dataself.next=None
Example: Below is a simple example to create a singly linked list with three nodes containing integer data.
classNode:def__init__(self,data):self.data=dataself.next=None# Create nodesnode1=Node(15)node2=Node(3)node3=Node(17)node4=Node(90)# Link nodesnode1.next=node2node2.next=node3node3.next=node4head=node1# Head points to the first node# Traverse and print the linked listcurrent=headwhilecurrent:print(current.data,end=" -> ")current=current.nextprint("None")
15 -> 3 -> 17 -> 90 -> None
Linked lists come in different forms depending on how nodes are connected. Each type has its own advantages and is used based on problem requirements. The main types of linked lists are:
To practice problems related to linked list, refer to this articleLinked List Data Structure
S
Python Introduction
Input and Output in Python
Python Variables
Python Operators
Python Keywords
Python Data Types
Conditional Statements in Python
Loops in Python - For, While and Nested Loops
Python Functions
Recursion in Python
Python Lambda Functions
Python String
Python Lists
Python Tuples
Python Dictionary
Python Sets
Python Arrays
List Comprehension in Python
Python OOP Concepts
Python Exception Handling
File Handling in Python
Python Database Tutorial
Python MongoDB Tutorial
Python MySQL
Python Packages
Python Modules
Python DSA Libraries
List of Python GUI Library and Packages
NumPy Tutorial - Python Library
Pandas Tutorial
Matplotlib Tutorial
Python Seaborn Tutorial
StatsModel Library - Tutorial
Learning Model Building in Scikit-learn
TensorFlow Tutorial
PyTorch Tutorial
Flask Tutorial
Django Tutorial | Learn Django Framework
Django ORM - Inserting, Updating & Deleting Data
Templating With Jinja2 in Flask
Django Templates
Build a REST API using Flask - Python
Building a Simple API with Django REST Framework
Python Quiz
Python Coding Practice
Python Interview Questions and Answers