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
Project details
Release history Release notifications | RSS feed
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.0.tar.gz
(9.6 kB
view details)
Built Distribution
File details
Details for the file zeroth-1.0.0.tar.gz
.
File metadata
- Download URL: zeroth-1.0.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a6f9e517f9e473264e4ec9a91026f7a18f346f237e27ccfccb9a90c3811948c |
|
MD5 | 206d5531dc8e4209bcdee12f6081f0fc |
|
BLAKE2b-256 | 4aecdf218ada17364453e8b9c18e7c6095ce76baad8f6700eb0a666cd8ef5c00 |
File details
Details for the file zeroth-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: zeroth-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba39e99954848a63c200d4fe2c2b65707609bbb82ed62a1a5d61880bfa0a502 |
|
MD5 | cf4fc091a376cecb672f491fcd187341 |
|
BLAKE2b-256 | 865c4bf0c19637217a1e925f1f5a0c390046d9c1926572fbd1ef8cbc6d1d4919 |