🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

defaultlist

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defaultlist

Automatically Extending List

1.2.0
Maintainers
1

PyPI Version Python Build Documentation Coverage Status python-versions contributors PRs Welcome Pull Requests Pull Requests Closed

Automatically Extending List

Getting started

List extending automatically to the maximum requested length.

Added indices 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 indices 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

Installing it is pretty easy:

pip install defaultlist

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts