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

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.0.0.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

zeroth-1.0.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page