On this page
  1. collections.UserList
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

collections.UserList

Prev: collections.UserDict | Up: collections | Next: collections.UserString
Rel: collections.ChainMap, collections.Counter, collections.defaultdict, collections.deque
Ref: docs.python.org — collections.UserList
Tags: #public #python3 #stdlib #collections


Import

import collections
from collections import UserList

Signature & Overview

collections.UserList(initlist=None)

A more or less complete user-defined wrapper around list objects.

Methods & Attributes

Usage

from collections import UserList

class UniqueList(UserList):
    def append(self, item) -> None:
        if item not in self.data:
            super().append(item)

u = UniqueList([1, 2])
u.append(2)
u.append(3)
assert list(u) == [1, 2, 3]

Gotchas

REPL Inspect

from collections import UserList
help(UserList)

Linked from

Related notes