Goulib.container module

advanced containers : Record (struct), SortedCollection, and INFINITE Sequence

class Goulib.container.Record(*args, **kwargs)[source]

Bases: collections.OrderedDict

mimics a Pascal record or a C struct

__init__(*args, **kwargs)[source]
__getattr__(name)[source]
__setattr__(name, value)[source]
__str__()[source]
__class__

alias of type

__contains__()

True if D has a key k, else False.

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__

Return self>value.

__hash__ = None
__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Return state information for pickling

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__reversed__() <==> reversed(od)
__setitem__

Set self[key] to value.

__sizeof__()
clear() → None. Remove all items from od.
copy() → a shallow copy of od
fromkeys(S[, v]) → New ordered dictionary with keys from S.

If not specified, the value defaults to None.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items()
keys()
move_to_end()

Move an existing element to the end (or beginning if last==False).

Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key).

pop(k[, d]) → v, remove specified key and return the corresponding

value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update()
values()
class Goulib.container.Sequence(iterf=None, itemf=None, containf=None, desc='')[source]

Bases: object

combines a generator and a read-only list used for INFINITE numeric (integer) sequences

Parameters:
  • iterf – optional iterator, or a function returning an iterator
  • itemf – optional function(i) returning the i-th element
  • containf – optional function(n) return bool True if n belongs to Sequence
  • desc – string description
__init__(iterf=None, itemf=None, containf=None, desc='')[source]
Parameters:
  • iterf – optional iterator, or a function returning an iterator
  • itemf – optional function(i) returning the i-th element
  • containf – optional function(n) return bool True if n belongs to Sequence
  • desc – string description
__repr__()[source]
save(filename, comment=None, n=1000, maxtime=10)[source]
__iter__()[source]

reset the generator

Returns:a tee-ed copy of iterf
__getitem__(i)[source]
index(v)[source]
__contains__(n)[source]
__add__(other)[source]
__sub__(other)[source]
__mul__(other)[source]
__div__(other)[source]
__or__(other)[source]
Returns:Sequence with items from both operands
__and__(other)[source]
Returns:Sequence with items in both operands
__mod__(other)[source]
Returns:Sequence with items from left operand not in right
apply(f, containf=None, desc='')[source]
filter(f, desc='')[source]
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

accumulate(op=<built-in function add>, skip_first=False)[source]
pairwise(op, skip_first=False)[source]
sort(key=None, buffer=100)[source]
unique(buffer=100)[source]
Parameters:buffer – int number of last elements found.

if two identical elements are separated by more than this number of elements in self, they might be generated twice in the resulting Sequence :return: Sequence made of unique elements of this one