Skip to content

Latest commit

 

History

History
96 lines (65 loc) · 2.76 KB

README.rst

File metadata and controls

96 lines (65 loc) · 2.76 KB
https://img.shields.io/pypi/dm/defaultlist.svg?label=pypi%20downloads https://readthedocs.org/projects/defaultlist/badge/?version=latest https://readthedocs.org/projects/defaultlist/badge/?version=1.1.0 https://img.shields.io/badge/linter-pylint-%231674b1?style=flat https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square

Documentation

The Documentation is hosted on http://defaultlist.readthedocs.io/en/1.1.0/

Getting started

List extending automatically to the maximum requested length.

Added indicies are filled with None by default.

>>> from defaultlist import defaultlist
>>> l = defaultlist()
>>> l
[]
>>> l[2] = "C"
>>> l
[None, None, 'C']
>>> l[4]
>>> l
[None, None, 'C', None, None]

Slices and negative indicies are supported likewise

>>> l[1:4]
[None, 'C', None]
>>> l[-3]
'C'

Simple factory functions can be created via lambda.

>>> l = defaultlist(lambda: 'empty')
>>> l[2] = "C"
>>> l[4]
'empty'
>>> l
['empty', 'empty', 'C', 'empty', 'empty']

Installation

To install the defaultlist module run:

pip install defaultlist

If you do not have write-permissions to the python installation, try:

pip install defaultlist --user