Skip to content

A Python3 MutableSequence, polymorphic singly linked list (for educational purposes)

License

Notifications You must be signed in to change notification settings

rswgnu/rsw_py_sll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rsw_py_sll

A Python3 MutableSequence, polymorphic singly linked list (for educational purposes) offering:

  • creation with any number of items: s1 = Sll(0, 1, 2); s2 = Sll()

  • numeric indexing of list items (0 or greater): s[0]

  • iteration: for item in s1

  • emptiness and boolean truthiness testing:
    s1.is_empty() returns False; s2.is_empty() returns True
    s1 and not s2 returns True

  • containment for finding if an item is in the list: if 2 in s1: print("found it")

  • concatenation with '+': s1 + s2

  • duplication and extending with '*': s1 * 2 returns Sll[0, 1, 2, 0, 1, 2]

  • prepending and extending by any number of items:
    s1.prepend(3, 4) returns Sll[3, 4, 0, 1, 2]
    s1.extend(5, 6) returns Sll[3, 4, 0, 1, 2, 5, 6]
    s2.extend(3, 4) returns Sll[3, 4]

  • appending single items: s2.append(5) returns Sll[3, 4, 5]

  • finding an item and returning its sublist: s2.find(4) returns Sll[4, 5]

  • counting item occurrences: s2.count(3) returns 1

  • list or item deletion via 'del': del s1[2] or del s1

  • access to last item or sublist:
    s2.last() returns 5
    s2.last_sublist() returns Sll[5]

  • conversion to a standard Python list of items: s2.items() returns [3, 4, 5]

  • a full set of self-tests: Sll.test().

About

A Python3 MutableSequence, polymorphic singly linked list (for educational purposes)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages