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.2.0.tar.gz (115.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.2.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zeroth-1.2.0.tar.gz
  • Upload date:
  • Size: 115.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.2.0.tar.gz
Algorithm Hash digest
SHA256 9d484a5f70800ab44189b5252401d18e9ce537c917081ee4e87dd86871d6b77f
MD5 4023cd7b1aa1e5d2ab10c83afb02e113
BLAKE2b-256 ded3e1cb496be02859e42763dd351e834f537a214e8deaebf0af247bbc2809f2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: zeroth-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5eb008cd02eb6e44a2387b5d5421d39a86a8abfc5eae8d1ca8d09b97f572a075
MD5 2f8621f797b4d590d0c5103e8fccb6d5
BLAKE2b-256 79663400e437c761dcfdc355d24620ae57d71fb29be0c339380864260069068e

See more details on using hashes here.

Provenance

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