cf.CfList

class cf.CfList(sequence=())

Bases: _abcoll.MutableSequence

A list-like object with attributes.

Initialization

Parameters :
sequence : iterable, optional

Define a new list with these elements.

CfList methods (undocumented methods behave exactly as their counterparts in a built-in list)

append
copy Return a deep copy.
count Return the number of occurrences of a given value.
equals True if two instances are equal, False otherwise.
extend
index Return the first index of a given value.
insert Insert an object before the given index in place.
pop
remove
reverse
copy()

Return a deep copy.

Equivalent to copy.deepcopy(s).

Returns :
out :

The deep copy.

Examples

>>> s.copy()
count(value)

Return the number of occurrences of a given value.

Uses numerically tolerant equality where appropriate.

Parameters :
value :

The value to count.

Returns :
out : int

The number of occurrences of value.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.count(1)
1
>>> s.count(2)
3
equals(other, rtol=None, atol=None, traceback=False)

True if two instances are equal, False otherwise.

Two instances are equal if their attributes are equal and their elements are equal pair-wise.

Parameters :
other :

The object to compare for equality.

atol : float, optional

The absolute tolerance for all numerical comparisons, By default the value returned by the ATOL function is used.

rtol : float, optional

The relative tolerance for all numerical comparisons, By default the value returned by the RTOL function is used.

traceback : bool, optional

If True then print a traceback highlighting where the two instances differ.

Returns :
out : bool

Whether or not the two instances are equal.

index(value, start=0, stop=None)

Return the first index of a given value.

Uses numerically tolerant equality where appropriate.

Parameters :
value :

The value to look for in the list.

start : int, optional

Start looking from this index. By default, look from the beginning of the list.

stop : int, optional

Stop looking before this index. By default, look up to the end of the list.

Returns :

out : int

Raises :
ValueError :

If the given value is not in the list.

Examples

>>> s
[1, 2, 3, 2, 4, 2]
>>> s.index(1)
1
>>> s.index(2, 2)
3
>>> s.index(2, start=2, stop=5)
3
>>> s.index(6)
ValueError: CfList doesn't contain: 6
insert(index, item)

Insert an object before the given index in place.

Parameters :

index : int

item :

Returns :

None

Examples

>>> s
[1, 2, 3]
>>> s.insert(1, 'A')
>>> s
[1, 'A', 2, 3]
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(100, 'B')
[1, 'A', 2, 3, 'B']
>>> s.insert(-2, 'C')
[1, 'A', 2, 'C', 3, 'B']
>>> s.insert(-100, 'D')
['D', 1, 'A', 2, 'C', 3, 'B']

Previous topic

cf.CfDict

Next topic

cf.Variable

This Page