# Linked List ```python= class Node: def __init__(self, key, value=None, next=None): self.key = key self.value = value self.next = next class LinkedList: def __init__(self, head: Node = None, tail: Node = None): self.head = head self.tail = tail def indexOf(self, key) -> int: current = self.head index = 0 while current is not None: if current.key == key: return index index += 1 current = current.next return -1 def add_list_item(self, item: Node) -> None: if not self.head: self.head = item else: self.tail.next = item self.tail = item list1 = LinkedList() print(list1.indexOf("b")) # >>> print(list1.indexOf("b")) # -1 list1.add_list_item(Node("a", "b")) list1.add_list_item(Node("b", "c")) print(list1.indexOf("b")) # >>> print(list1.indexOf("b")) # 1 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up