Skip to main content

named_sequence - list like object allowing selection by name and index

This package contains the class NamedSequence.
This class reproduces the behaviour of a list (from which it inherits) but most list special functions such as _getitem_ allow name and index as argument.
Methods formerly returning list (such as slicing with _getitem_ or copy) now return a NamedSequence instance.

NamedSequence instances requires an additional argument : the name of the method of the items to get their name.

Basic usage

Instanciation

from named_sequence import NamedSequence

class NamedItem(object):  # Used only to illusrate the behaviour
    def __init__(self, name):
        self.__name = name

    def get_name(self):
        return self.__name

the_instance = NamedSequence((NamedItem("a"), NamedItem("b")), "get_name")

getting or setting items

a1 = the_instance["a"]
a2 = the_instance[0]
a1 is a2
>>> True

the_instance["b"] = NamedItem("a")
the_instance["b"] = NamedItem("d")  # the name "b" no more exists
>>> KeyError: "No item named 'b' !

the_instance["a"] = NamedItem("a2")  # When name are present several time, the fist occurence is considered
for elem in the_instance:
    print(elem.get_name())
>>> a2
>>> a

Release files for named-sequence 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for named-sequence 1.0
File Interpreter ABI Platform
named_sequence-1.0-py3-none-any.whl Python 3 none any Details

Release files / named_sequence-1.0-py3-none-any.whl

Download URL named_sequence-1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b9586930f55a71a193e4aada3e20225fc9bad80104547d21ebb07ab1f977d2b
BLAKE2b-256 checksum
How to use checksums
02c8d0eb2a5cb94d0a361a25b32b39ef73f5aea7ded61cce7416ba8f785dc738
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.3

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page