schrodinger.utils.scollections module¶
-
class
schrodinger.utils.scollections.
IdSet
(initial_set=None)¶ Bases:
collections.abc.MutableSet
,set
An id set is a set that uses the id of an object as the key instead of the hash. This means that two objects that compare equal but are different instances will be stored separately since id(obj1) != id(obj2).
NOTE: Using this set with python’s builtin immutable datatypes is /strongly/ discouraged (e.g. str and int are not guaranteed to have different ids for separate instances)
-
copy
()¶ Return a shallow copy of a set.
-
classmethod
fromIterable
(iterable)¶
-
isdisjoint
(other)¶ Return True if two sets have a null intersection.
-
issubset
(other)¶ Report whether another set contains this set.
-
issuperset
(other)¶ Report whether this set contains another set.
-
union
(*other_sets)¶ Return the union of sets as a new set.
(i.e. all elements that are in either set.)
-
intersection
(*other_sets)¶ Return the intersection of two sets as a new set.
(i.e. all elements that are in both sets.)
-
difference
(*other_sets)¶ Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)
-
symmetric_difference
(*other_sets)¶ Return the symmetric difference of two sets as a new set.
(i.e. all elements that are in exactly one of the sets.)
-
update
(*other_sets)¶ Update a set with the union of itself and others.
-
intersection_update
(*other_sets)¶ Update a set with the intersection of itself and another.
-
difference_update
(*other_sets)¶ Remove all elements of another set from this set.
-
symmetric_difference_update
(*other_sets)¶ Update a set with the symmetric difference of itself and another.
-
add
(obj)¶ Add an element.
-
discard
(obj)¶ Remove an element. Do not raise an exception if absent.
-
-
class
schrodinger.utils.scollections.
IdItemsView
(id_dict, id_map)¶ Bases:
collections.abc.ItemsView
-
class
schrodinger.utils.scollections.
IdDict
(initial_dict=None)¶ Bases:
collections.abc.MutableMapping
,dict
An id dict is a dictionary that uses the id of an object as the key instead of the hash. This means that two objects that compare equal but are different instances will be stored separately since id(obj1) != id(obj2).
NOTE: Using this dict with python’s builtin immutable datatypes is /strongly/ discouraged (e.g. str and int are not guaranteed to have different ids for separate instances)
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
has_key
(obj)¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
updateFromIterable
(iterable)¶
-
classmethod
fromIterable
(iterable)¶
-
clear
() → None. Remove all items from D.¶
-
-
class
schrodinger.utils.scollections.
DefaultIdDict
(default_factory)¶ Bases:
schrodinger.utils.scollections.IdDict
A dict that is both an id dict and a defaultdict.
-
classmethod
fromIterable
(iterable)¶
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
classmethod
-
class
schrodinger.utils.scollections.
DefaultFactoryDictMixin
(factory_func, *args, **kwargs)¶ Bases:
object
A mixin to use with
dict
’s that allows the dict to use a factory function similar todefaultdict
. The key distinction here is that the factory function will be passed the key itself instead of called without any arguments.Note
Despite the name, this mixin works with classes as well. When passed a class, the constructor will be called and passed the keys.
Warning
This mixin will not work with factory functions that expect only one tuple as an argument. This is due to the way
__getitem__
packages up all keys in a single call into one tuple.
-
class
schrodinger.utils.scollections.
DefaultFactoryDict
(factory_func, *args, **kwargs)¶ Bases:
schrodinger.utils.scollections.DefaultFactoryDictMixin
,dict
A basic
dict
using theDefaultFactoryDictMixin
. This is separated from the mixin to allow otherdict
subclasses to easily subclassDefaultFactoryDictMixin
.- Example usage::
- stringified_objs = DefaultFactoryDict(str) assert 1 not in stringified_objs print(stringified_objs[1]) # ‘1’