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.1.0.tar.gz (132.5 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.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zeroth-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e57cd4dba6a2be404da3dfdff487a46a5ad9b278718ffb636af9a81a323e54c7
MD5 fca0b210ca869d5f5fe19bf24feeb8d2
BLAKE2b-256 93566cb5f7d42030b6be13e2df2933770893dc47e9f3bf856c54b3aa24494063

See more details on using hashes here.

Provenance

The following attestation bundles were made for zeroth-1.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: zeroth-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71ddd51a06c0a3552dc0f7e885f5c9932b25be47d1d9ec435a4ca6033e59f13a
MD5 4dfb1f6d0646a1a137cc49e76734ab8b
BLAKE2b-256 89db0f740959563e8b7836d9c335e889653ccfca97c4e4661ec19dec0744a3af

See more details on using hashes here.

Provenance

The following attestation bundles were made for zeroth-1.1.0-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