This is a micro-package, containing the single function zeroth
.
zeroth
is syntactic sugar for next(iter(obj))
, with a nice docstring.
pip install zeroth
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