Learn practical skills, build real-world projects, and advance your career

Introduction to Python Classes and Linked Lists

Part 2 of "Data Structures and Algorithms in Python"

Data Structures and Algorithms in Python is beginner-friendly introduction to common data structures (linked lists, stacks, queues, graphs) and algorithms (search, sorting, recursion, dynamic programming) in Python, designed to help you prepare for coding interviews and assessments. Check out the full series here:

  1. Binary Search and Complexity Analysis
  2. Python Classes and Linked Lists
  3. Arrays, Stacks, Queues and Strings (coming soon)
  4. Binary Search Trees and Hash Tables (coming soon)
  5. Insertion Sort, Merge Sort and Divide-and-Conquer (coming soon)
  6. Quicksort, Partitions and Average-case Complexity (coming soon)
  7. Recursion, Backtracking and Dynamic Programming (coming soon)
  8. Knapsack, Subsequence and Matrix Problems (coming soon)
  9. Graphs, Breadth-First Search and Depth-First Search (coming soon)
  10. Shortest Paths, Spanning Trees & Topological Sorting (coming soon)
  11. Disjoint Sets and the Union Find Algorithm (coming soon)
  12. Interview Questions, Tips & Practical Advice (coming soon)

How to Run the Code

The best way to learn the material is to execute the code and experiment with it yourself. This tutorial is an executable Jupyter notebook. You can run this tutorial and experiment with the code examples in a couple of ways: using free online resources (recommended) or on your computer.

Option 1: Running using free online resources (1-click, recommended)

The easiest way to start executing the code is to click the Run button at the top of this page and select Run on Binder. You can also select "Run on Colab" or "Run on Kaggle", but you'll need to create an account on Google Colab or Kaggle to use these platforms.

Option 2: Running on your computer locally

To run the code on your computer locally, you'll need to set up Python, download the notebook and install the required libraries. We recommend using the Conda distribution of Python. Click the Run button at the top of this page, select the Run Locally option, and follow the instructions.

Jupyter Notebooks: This notebook is made of cells. Each cell can contain code written in Python or explanations in plain English. You can execute code cells and view the results instantly within the notebook. Jupyter is a powerful platform for experimentation and analysis. Don't be afraid to mess around with the code & break things - you'll learn a lot by encountering and fixing errors. You can use the "Kernel > Restart & Clear Output" menu option to clear all outputs and start again from the top.

Problem

In this notebook, we'll focus our discussion on the following problem:

QUESTION: Write a function to reverse a linked list

Before we answer this question, we need to answer:

  • What do we mean by linked list?
  • How do we create a linked list in Python?
  • How do we store numbers in a linked list?
  • How do we retrieve numbers in a linked list
!pip install jovian --upgrade --quiet
import jovian