llist

raw JSON →
0.7.1 verified Fri May 01 auth: no python

Provides implementations of linked list data structures for Python, including singly linked list, doubly linked list, and doubly linked list with a sentinel node. Version 0.7.1 is the latest release; the library is stable but infrequently updated.

pip install llist
error AttributeError: module 'llist' has no attribute 'dllist'
cause Import path is incorrect; some users try `import llist` and then use `llist.dllist` but it may not be imported automatically.
fix
Use from llist import dllist or import llist; d = llist.dllist().
error TypeError: 'sllist' object is not subscriptable
cause Trying to index into a singly linked list like a Python list.
fix
Convert to list first: list(s)[index].
error AttributeError: 'sllist' object has no attribute 'len'
cause Calling `len(s)` on an sllist object; len() is not defined.
fix
Use s.size() or len(list(s)).
gotcha The `sllist` and `dllist` classes do not support `len()` in Python 3. Use `sllist.size()` method instead.
fix Use `len(list(s))` or `s.size()` to get the length.
gotcha The `dllist` does not support indexing (e.g., `d[0]`) because it is not a sequence. Access elements via iteration or conversion to list.
fix Use `list(d)[0]` or iterate over the list.
breaking In version 0.7, the `sllist` and `dllist` no longer support direct slicing like Python built-in lists. Attempting to slice will raise a TypeError.
fix Convert to list first: `list(mylist)[start:stop]`.
gotcha The `llist` module uses the name `dllist` which conflicts in some IDEs with the concept of a doubly linked list. No actual library conflict, but users sometimes confuse with `deque` from collections.
fix Remember `llist.dllist` is a linked list, not the `collections.deque`.

Create singly and doubly linked lists, append elements, and convert to list.

from llist import sllist, dllist

# Singly linked list
s = sllist([1, 2, 3, 4, 5])
print('sllist:', list(s))
s.append(6)
print('After append:', list(s))

# Doubly linked list
d = dllist([10, 20, 30])
print('dllist:', list(d))
d.appendright(40)
print('After appendright:', list(d))