BishopPhillips
BishopPhillips
BPC Home BPC RiskManager BPC SurveyManager BPC RiskWiki Learn HTML 5 and CSS Enquiry

Programming in Python

An Introduction.

Python

As part of our cross-over to Python for software development we are putting together some opensource notes and libraries. This page consolidates that work. Here you will find a growing list of opensource python libraries and modules provided by BPC. All modules come with additional unit test and example use modules in the zip files.

 

Articles on Python Techniques

Below is an adhoc, essentially unsorted, list of articles we have written covering various Python programming techniques. As the list grows we shall make it more organised.

  1. Python Techniques - Function and Method Overloading in Python
  2. Python Techniques - Type checking in Python
  3. Python Techniques - List Comprehension
  4. Python Techniques - Dictionary Comprehension
  5. Python Techniques - Python Iterators
  6. Python Techniques - Python Generators
  7. Python Techniques - Python Closures
  8. Python Techniques - Python Maps and Filters
  9. Python Techniques - Refactoring With Generators
  10. Python Techniques - Classic Data Structures & Algorithms
  11. Python Techniques - Python Decorators

Programming in Python

Additional Resources.

  1. General Programming - GitHub for Newbies

DList

Doubly Linked List

Stakeholder Model

DLinkedList - Doubly Linked List

Author: Jonathan Bishop

Version: 1.0

Copyright: Jonathan Bishop 2025

Free for use by anyone for any purpose under the condition that Jonathan Bishop as author & creator is acknowledged in project documentation and on the about / credits screens of the project along with other module credits.

DlinkedList provides a doubly linked list that emulates the functionality of standard python lists, with some additional capabilities. Any iterable type can be provided as the initialiser argument and it will be converted to a doubly linked list. Any iterable can also be used as the right hand side of comparatives, additions, subtractions, etc. and it will be added to or subtracted from the list as appropriate. The class comes with both forward and reverse iteration support, which can be switched mid iteration, so the list can be used as an oscillator. The iterator also checks for a user defined "next" and "prev" function, so the next node in each iteration can be selected as a result of that function. This raises the possibility of having a one node list that is algorithmically infinite (and oscillating)! It would look like an infinite list to python. The objective was to make this object blend in seemlessly with other mutable python objects, so all enumeratable capabilities have been implemented. The list can store any python objects as its members.

Although it is actually a linked list of nodes, the library is designed to look like an array - similar to python lists.

The module comes with two additional files. One is a unittest object - for testing code changes, and the other is a set of tests designed to demonstrate some of its capabilities (and test stuff is working)

Usage:

  • my_list1 = DLList([1,2,3,4,5]) #Initiate - from list
  • my_list2 = DLList((1,2,3,4,5)) #Initiate - from tuple
  • my_list3 = DLList("abcdef") #Initiate - from string
  • my_list4 = my_list1 + my_list2 #Join two lists
  • my_list5 = my_list1.copy() #copy a list
  • my_list5 += my_list4 #Add to a list
  • my_list5 -= my_list4 #Subtract everything in list4 from list5
  • my_list5 = my_list5 * 3 #List5 duplicated 3 times
  • print(my_list5) #Print list5
  • my_list5.reverse() #Reverse the list order
  • my_list5.sort() #Sort list
  • if my_list1 < my_list5: print("Hello") #Six comparatives at list and node level.
  • my_list1.set_reverse(True) #turns the iterator into a backwards iterator
  • for val in my_list1: print(val) #Iterate through the list
  • list_of_even_indexes = my_list1.filter(lambda x: ((x % 2) == 0)) #indexes DLLFilter.INDEXES
  • list_of_even_nodes = my_list1.filter(lambda x: ((x % 2) == 0), DLLFilter.NODES)
  • list_of_even_values = my_list1.filter(lambda x: ((x % 2) == 0), DLLFilter.VALUES)
  • doubled_value_dlist = my_list1.map(lambda x: x * 2)
    #Apply a function to every node in the list
  • ALSO: my_list1[1], my_list1[1:3], del my_list1[2], my_list1[-1], etc. to_list(), in, append(), insert(), len(), sep(), remove(), remove_node() push(), pop(), peek(), merge(), splice(), first(), last(), index(), find()
.
...Download here....