orderingdict

OrderedDict subclass with predefined ordering


Keywords
dict, pypi, python, python-library
License
BSD-3-Clause
Install
pip install orderingdict==1.0.1

Documentation

CodeFactor CodeClimate Scrutinizer BetterCodeHub Sonarcloud

Codecov CircleCI Scrutinizer Semaphore CI Travis

Install

$ [sudo] pip install orderingdict

Features

  • order by ordering keys list
  • OrderingDict class and orderingdict(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')])

Sources