OpenQuizz
Une application de gestion des contenus pédagogiques
_PListBase Class Reference
Inheritance diagram for _PListBase:
Collaboration diagram for _PListBase:

Public Member Functions

def __reduce__ (self)
 
def __len__ (self)
 
def __repr__ (self)
 
def cons (self, elem)
 
def mcons (self, iterable)
 
def reverse (self)
 
def split (self, index)
 
def __iter__ (self)
 
def __lt__ (self, other)
 
def __eq__ (self, other)
 
def __getitem__ (self, index)
 
def __hash__ (self)
 
def remove (self, elem)
 

Static Public Attributes

 count
 
 index
 

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)
Traverses the lists, checking equality of elements.

This is an O(n) operation, but preserves the standard semantics of list equality.

◆ __getitem__()

def __getitem__ (   self,
  index 
)

◆ __hash__()

def __hash__ (   self)

◆ __iter__()

def __iter__ (   self)

◆ __len__()

def __len__ (   self)
Return the length of the list, computed by traversing it.

This is obviously O(n) but with the current implementation
where a list is also a node the overhead of storing the length
in every node would be quite significant.

◆ __lt__()

def __lt__ (   self,
  other 
)

◆ __reduce__()

def __reduce__ (   self)

◆ __repr__()

def __repr__ (   self)

◆ cons()

def cons (   self,
  elem 
)
Return a new list with elem inserted as new head.

>>> plist([1, 2]).cons(3)
plist([3, 1, 2])

◆ mcons()

def mcons (   self,
  iterable 
)
Return a new list with all elements of iterable repeatedly cons:ed to the current list.
NB! The elements will be inserted in the reverse order of the iterable.
Runs in O(len(iterable)).

>>> plist([1, 2]).mcons([3, 4])
plist([4, 3, 1, 2])

◆ remove()

def remove (   self,
  elem 
)
Return new list with first element equal to elem removed. O(k) where k is the position
of the element that is removed.

Raises ValueError if no matching element is found.

>>> plist([1, 2, 1]).remove(1)
plist([2, 1])

◆ reverse()

def reverse (   self)
Return a reversed version of list. Runs in O(n) where n is the length of the list.

>>> plist([1, 2, 3]).reverse()
plist([3, 2, 1])

Also supports the standard reversed function.

>>> reversed(plist([1, 2, 3]))
plist([3, 2, 1])

◆ split()

def split (   self,
  index 
)
Spilt the list at position specified by index. Returns a tuple containing the
list up until index and the list after the index. Runs in O(index).

>>> plist([1, 2, 3, 4]).split(2)
(plist([1, 2]), plist([3, 4]))

Field Documentation

◆ count

count
static

◆ index

index
static

The documentation for this class was generated from the following file: