Python Language Linked List Node Write a simple Linked List Node in python

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A linked list is either:

  • the empty list, represented by None, or
  • a node that contains a cargo object and a reference to a linked list.
#! /usr/bin/env python

class Node: 
      def __init__(self, cargo=None, next=None): 
          self.car = cargo 
          self.cdr = next    
      def __str__(self): 
          return str(self.car)


      def display(lst):
          if lst:
             w("%s " % lst)
             display(lst.cdr)
          else:
             w("nil\n")


Got any Python Language Question?