Skip to main content

collections.defaultdict equivalent implementation of list.

Project description

https://travis-ci.org/c0fec0de/defaultlist.svg?branch=master https://readthedocs.org/projects/defaultlist/badge/?version=1.0.0 https://codeclimate.com/github/c0fec0de/defaultlist.png https://landscape.io/github/c0fec0de/defaultlist/master/landscape.svg?style=flat

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
defaultlist-1.0.0.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None Nov 25, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page