From the course: Python Data Structures: Linked Lists
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Building a Linked List in Python - Python Tutorial
From the course: Python Data Structures: Linked Lists
Building a Linked List in Python
- [Instructor] Up until now. Linked lists have only been a theory, but here we're going to put it into practice. The first thing we're going to want to start with is a node, class node. This represents a node or an element within our linked list. Let's give it constructor. All right, so we're going to have two attributes. The first is a data attribute, self dot data equals data. And then the next is a pointer, the next pointer, self dot next. And we're going to leave this as none for now. So when we make a new node, it doesn't have a next pointer unless we give it one later. Okay, so great, we can make a new linked list by doing this. Node one, N dot next equals node two. So now we're populating our next pointers. Dot next dot next equals node three. All right, course over, everyone can go home now. Oh, you want more linked lists? Okay, well fine. While this is technically all you need to make a linked list, they generally have useful features associated with them. So let's add some…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.