17.1.1.1.2.2. cobra.core.dictlist
¶
17.1.1.1.2.2.1. Module Contents¶
17.1.1.1.2.2.1.1. Classes¶
A combined dict and list |
-
class
cobra.core.dictlist.
DictList
(*args)[source]¶ Bases:
list
A combined dict and list
This object behaves like a list, but has the O(1) speed benefits of a dict when looking up elements by their id.
-
_check
(self, id)[source]¶ make sure duplicate id’s are not added. This function is called before adding in elements.
-
query
(self, search_function, attribute=None)[source]¶ Query the list
- Parameters
search_function (a string, regular expression or function) – Used to find the matching elements in the list. - a regular expression (possibly compiled), in which case the given attribute of the object should match the regular expression. - a function which takes one argument and returns True for desired values
attribute (string or None) – the name attribute of the object to passed as argument to the search_function. If this is None, the object itself is used.
- Returns
a new list of objects which match the query
- Return type
Examples
>>> import cobra.test >>> model = cobra.test.create_test_model('textbook') >>> model.reactions.query(lambda x: x.boundary) >>> import re >>> regex = re.compile('^g', flags=re.IGNORECASE) >>> model.metabolites.query(regex, attribute='name')
-
_extend_nocheck
(self, iterable)[source]¶ extends without checking for uniqueness
This function should only be used internally by DictList when it can guarantee elements are already unique (as in when coming from self or other DictList). It will be faster because it skips these checks.
-
__sub__
(self, other)[source]¶ x.__sub__(y) <==> x - y
- Parameters
other (iterable) – other must contain only unique id’s present in the list
-
__isub__
(self, other)[source]¶ x.__sub__(y) <==> x -= y
- Parameters
other (iterable) – other must contain only unique id’s present in the list
-
__add__
(self, other)[source]¶ x.__add__(y) <==> x + y
- Parameters
other (iterable) – other must contain only unique id’s which do not intersect with self
-
__iadd__
(self, other)[source]¶ x.__iadd__(y) <==> x += y
- Parameters
other (iterable) – other must contain only unique id’s whcih do not intersect with self
-
__getstate__
(self)[source]¶ gets internal state
This is only provided for backwards compatibility so older versions of cobrapy can load pickles generated with cobrapy. In reality, the “_dict” state is ignored when loading a pickle
-
__setstate__
(self, state)[source]¶ sets internal state
Ignore the passed in state and recalculate it. This is only for compatibility with older pickles which did not correctly specify the initialization class
-