Skip to main content

minmax(x): min(x), max(x) in one pass

Project description

pyminmax

minmax(iterable, *, key=None)
minmax(iterable, *, default, key=None)
minmax(arg1, arg2, *args, key=None)

With a single iterable argument, return its smallest and largest items as a tuple pair. The default keyword-only argument specifies an object to return if the provided iterable is empty. If the iterable is empty and default is not provided, a ValueError is raised.

With two or more arguments, return the smallest and largest arguments as a tuple pair.

The key argument specifies a one-argument ordering function like that used for list.sort().

If multiple items are minimal or maximal, the function returns the first ones encountered.

It is written in C, adapted straight from CPython's implementation of min(), max().

Installation

pip install pyminmax

Basic Usage

>>> from pyminmax import minmax
>>> minmax([5, 2, 0, 100, -100, 10])
(-100, 100)
>>> minmax((), default=1)
1
>>> minmax(5, 2, 0, 100, -100, 10)
(-100, 100)
>>> minmax(5, 2, 0, 100, -100, 10, key=lambda x: -x)
(100, -100)

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

pyminmax-0.1.5.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyminmax-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (11.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file pyminmax-0.1.5.tar.gz.

File metadata

  • Download URL: pyminmax-0.1.5.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pyminmax-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5ecdb8c3559c7ef7157ddabf6f03322547542a53ccfe346e58d2ab1543083de2
MD5 a16a1ed212d2f64c7d072ea3a8d7c7da
BLAKE2b-256 b6c6a3d35168afc62f0764ad0f591ee97154bd089485a3af917054db364f6977

See more details on using hashes here.

File details

Details for the file pyminmax-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyminmax-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e475e693d1348600b58844b32e67551233ac7df0ae5f8fbe1165024d5965248b
MD5 c745974e78edd374f8e5243b66958b6e
BLAKE2b-256 7b9a70510933fe39ffa6eb0c6c11eb7facae6a704503f3cd84876b6f0b590cbc

See more details on using hashes here.

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