Skip to main content

list like object allowing selection by name and index

Project description

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

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

named_sequence-1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file named_sequence-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for named_sequence-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b9586930f55a71a193e4aada3e20225fc9bad80104547d21ebb07ab1f977d2b
MD5 80606b3cef7b07ff4cedd2334f3a10f0
BLAKE2b-256 02c8d0eb2a5cb94d0a361a25b32b39ef73f5aea7ded61cce7416ba8f785dc738

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page