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
pip install zeroth
Documentation
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e5edec7a4e8362b203b91eadcb63b3b61e6b94e7a98c569c3314e50982a0f3c
|
|
| MD5 |
b045342f1daf6ba0e9980efaf4326907
|
|
| BLAKE2b-256 |
073f68d1d1ddecc7e2bfe4546c1a4b2f7ba7e422698ade7856875e4ad58c9783
|
Provenance
The following attestation bundles were made for zeroth-1.0.1.tar.gz:
Publisher:
cd.yml on GalacticDynamics/zeroth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zeroth-1.0.1.tar.gz -
Subject digest:
6e5edec7a4e8362b203b91eadcb63b3b61e6b94e7a98c569c3314e50982a0f3c - Sigstore transparency entry: 583965893
- Sigstore integration time:
-
Permalink:
GalacticDynamics/zeroth@23a86b7e6081144836f691fd5ed82f5fc41f036b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@23a86b7e6081144836f691fd5ed82f5fc41f036b -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4edd4308fbd98c4b41d9c5537ab8b33518164565171abfdd095f9564556e2bca
|
|
| MD5 |
23ad1e7fefb882513870d78bcdf87ce2
|
|
| BLAKE2b-256 |
74156f72bb25034e7984d4197caa194cf1a110ade5988018f6be0dade726d18c
|
Provenance
The following attestation bundles were made for zeroth-1.0.1-py3-none-any.whl:
Publisher:
cd.yml on GalacticDynamics/zeroth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zeroth-1.0.1-py3-none-any.whl -
Subject digest:
4edd4308fbd98c4b41d9c5537ab8b33518164565171abfdd095f9564556e2bca - Sigstore transparency entry: 583965901
- Sigstore integration time:
-
Permalink:
GalacticDynamics/zeroth@23a86b7e6081144836f691fd5ed82f5fc41f036b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@23a86b7e6081144836f691fd5ed82f5fc41f036b -
Trigger Event:
release
-
Statement type: