Skip to main content

Efficiently get the index-0 element of an iterable.

Project description

zeroth

Efficiently get the index-0 element of an iterable.

This is a micro-package, containing the single function zeroth.
zeroth is syntactic sugar for next(iter(obj)), with a nice docstring.

Installation

PyPI platforms PyPI version

pip install zeroth

Documentation

Actions Status

from zeroth import zeroth

print(zeroth([0, 1, 2]))
# 0

print(zeroth((3, 2, 1)))
# 3

print(zeroth({"a": 1, "b": 2, "c": 3}))
# 'a'

print(zeroth(range(3)))
# 0

print(zeroth(range(1, 3)))
# 1

print(zeroth(map(str, range(3))))
# '0'

import numpy as np

print(zeroth(np.array([1, 2, 3])))
# 1


class ReverseIterable:
    def __init__(self, data):
        self.data = data

    def __iter__(self):
        return iter(reversed(self.data))


print(zeroth(ReverseIterable([1, 2, 3])))
# 3

Q&A

Why isn't this called first since it gets the element with ordinality of 1?

Because that package name is already taken on PyPI. Here zeroth refers to the index.

Project details


Download files

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

Source Distribution

zeroth-1.0.1.tar.gz (88.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zeroth-1.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file zeroth-1.0.1.tar.gz.

File metadata

  • Download URL: zeroth-1.0.1.tar.gz
  • Upload date:
  • Size: 88.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zeroth-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6e5edec7a4e8362b203b91eadcb63b3b61e6b94e7a98c569c3314e50982a0f3c
MD5 b045342f1daf6ba0e9980efaf4326907
BLAKE2b-256 073f68d1d1ddecc7e2bfe4546c1a4b2f7ba7e422698ade7856875e4ad58c9783

See more details on using hashes here.

Provenance

The following attestation bundles were made for zeroth-1.0.1.tar.gz:

Publisher: cd.yml on GalacticDynamics/zeroth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zeroth-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: zeroth-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zeroth-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4edd4308fbd98c4b41d9c5537ab8b33518164565171abfdd095f9564556e2bca
MD5 23ad1e7fefb882513870d78bcdf87ce2
BLAKE2b-256 74156f72bb25034e7984d4197caa194cf1a110ade5988018f6be0dade726d18c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zeroth-1.0.1-py3-none-any.whl:

Publisher: cd.yml on GalacticDynamics/zeroth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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