OrderedNamedTypedDict
- class ipkiss3.all.OrderedNamedTypedDict
Dict with named items of a given type.
The name of the item becomes the key into the dictionary. Items can be retrieved with [] both by name and by int key
Behaves partially as a list in that it supports the append() and extend() methods, as well as the += operator.
Enforces unique names/keys. When comparing two dictionaries, order is taken into account. Observes name changes of its item values, changing the keys in the dictionary when a name of an item changes.
Examples
class MyNamedType(object): def __init__(self, name): self.name = name def __repr__(self): return "I am {0}".format(self.name) class MyOrderdNamedDict(OrderedNamedTypedDict): _item_type = MyNamedType my_list = MyOrderdNamedDict() my_list.append(MyNamedType(name="one")) my_list += MyNamedType(name="two") my_list.extend([MyNamedType(name="three"), MyNamedType(name="four")]) print(my_list["one"]) print(my_list[0])