-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
A Linked List is a linear data structure where elements (called nodes) are connected using pointers.
Each node contains:
Data
A pointer to the next node
It follows a sequential order, but unlike arrays, it does not use continuous memory.
Dynamic size
Efficient insert/delete from start or middle
No need to shift elements (like in arrays)
A simple node in Python is created using a class:
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Define node
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Create linked list
node1 = Node(10)
node2 = Node(20)
node3 = Node(30)
# Connect nodes
node1.next = node2
node2.next = node3
# Traverse list
current = node1
while current:
print(current.data)
current = current.next
✅ Output:
10
20
30
def traverse(head):
current = head
while current:
print(current.data)
current = current.next
new_node = Node(5)
new_node.next = node1 # node1 was the previous head
head = new_node
def insert_end(head, data):
new = Node(data)
current = head
while current.next:
current = current.next
current.next = new
def delete_node(head, key):
if head.data == key:
return head.next
prev = None
current = head
while current and current.data != key:
prev = current
current = current.next
if current:
prev.next = current.next
return head
Q1. Write a Python program to create a linked list with 4 nodes having values: 10, 20, 30, and 40.
Q2. Write a Python program to define a function that displays all values in the linked list.
Q3. Write a Python program to insert a new node at the beginning of the linked list.
Q4. Write a Python program to insert a new node at the end of the linked list.
Q5. Write a Python program to delete a node with value 20 from the linked list.
Q6. Write a Python program to count the total number of nodes in the linked list.
Q7. Write a Python program to check if a specific value exists in the linked list.
Q8. Write a Python program to reverse the linked list.
Q9. Write a Python program to create a function that searches a node by value and returns its position.
Q10. Write a Python program to print the value of the last node in the linked list.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms