Install
$ [sudo] pip install orderingdict
Features
- order by ordering keys list
-
OrderingDict
class andorderingdict(ordering, *args, **kwargs)
function
Examples
subclassing
>>> from orderingdict import OrderingDict
>>> class Metadata(OrderingDict):
ordering = ["name", "version", "url"]
>>> metadata = Metadata(url='https://github.com/owner/repo,version="1.0.0",name='pkgname')
Metadata([('name', 'pkgname'), ('version', '1.0.0'), ('url', 'https://github.com/owner/repo')])
creating instance with orderingdict(ordering, *args, **kwargs)
function
>>> from orderingdict import orderingdict
>>> ordering = ["name", "version", "url"]
>>> metadata = dict(url='https://github.com/owner/repo,version="1.0.0",name='pkgname')
{'url': 'https://github.com/owner/repo', 'version': '1.0.0', 'name': 'pkgname'}
>>> orderingdict(ordering, metadata)
OrderingDict([('name', 'pkgname'), ('version', '1.0.0'), ('url', 'https://github.com/owner/repo')])