Goulib.container module

advanced containers : Record (struct), 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]

Initialize self. See help(type(self)) for accurate signature.

__getattr__(name)[source]
__setattr__(name, value)[source]

Implement setattr(self, name, value).

__str__()[source]

Return str(self).

__class__

alias of builtins.type

__contains__()

True if the dictionary has the specified key, else False.

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__()

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
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__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__() → size of D in memory, in bytes
clear() → None. Remove all items from od.
copy() → a shallow copy of od
fromkeys()

Create a new ordered dictionary with keys from iterable and values set to value.

get()

Return the value for key if key is in the dictionary, else default.

items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
move_to_end()

Move an existing element to the end (or beginning if last is false).

Raise KeyError if the element does not exist.

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()

Remove and return a (key, value) pair from the dictionary.

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

setdefault()

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values
class Goulib.container.Sequence(iterf=None, itemf=None, containf=None, desc='', timeout=0)[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='', timeout=0)[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]

Return repr(self).

save(filename, comment=None, n=1000, maxtime=10)[source]
__iter__()[source]

reset the generator

Returns:a tee-ed copy of iterf, optionally timeout decorated
__getitem__(i)[source]
index(v)[source]
__contains__(n)[source]
__add__(other)[source]
__sub__(other)[source]
__mul__(other)[source]
__div__(other)[source]
__truediv__(other)[source]
__or__(other)[source]
Returns:Sequence with items from both (sorted) operand Sequences
__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]

function composition

__call__(other)[source]

Call self as a function.

filter(f, desc='')[source]
__le__(other)[source]

Return self<=value.

__gt__(other)[source]

Return self>value.

accumulate(op=<built-in function add>, init=[])[source]
pairwise(op, skip_first=False)[source]
sort(key=None, buffer=100)[source]
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__

Return self==value.

__format__()

Default object formatter.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__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__()

Size of object in memory, in bytes.

__str__

Return str(self).

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

product(other, op=<built-in function sum>, buffer=100)[source]

cartesian product