Skip to content

Instantly share code, notes, and snippets.

@AloofBuddha
Created November 13, 2014 08:54
Show Gist options
  • Save AloofBuddha/d95ad453031b860c484b to your computer and use it in GitHub Desktop.
Save AloofBuddha/d95ad453031b860c484b to your computer and use it in GitHub Desktop.
Linked List search in Python
# we want to match data, not a Node, as search
# shouldn't require any Node creation either
def search(self, data):
node = self.head
while node:
if node.data == data:
return node
else:
node = node.nextNode
else:
raise ValueError("No node with matching data found in Linked List")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment