tailrec
Provides a decorator tailrec which executes a tail recursive function iteratively
Installation
pip install tailrec
Examples
from tailrec import tailrec
@tailrec
def factorial(n: int, accum: int = 1) -> int:
"""Calculates n!"""
if n == 0:
return accum
else:
return factorial(n - 1, accum * n)
@tailrec
def fibonacci(n: int, current: int = 0, next_: int = 1) -> int:
"""Returns the n-th number of the fibonacci sequence"""
if n == 0:
return current
else:
return fibonacci(n - 1, next_, current + next_)
print(factorial(5)) # 120
print(factorial(1_100)) # 5343708488092637703...
print(fibonacci(5)) # 8
print(fibonacci(2_000)) # 42246963333923...
Metadata
Release files for tailrec 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tailrec-0.1.6.tar.gz | 3.0 kB | Without provenance | Details for tailrec-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tailrec-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for tailrec-0.1.6-py3-none-any.whl |
Total release size: 8.0 kB
Release files / tailrec-0.1.6.tar.gz
| Download URL | tailrec-0.1.6.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9405770a13c110c4832a488a13267741b353afef3c1e7b1f3c279099e0eba7e2
|
|
BLAKE2b-256 checksum How to use checksums |
e07e8709c06869be11f08d5d81b5a74eb6c4386a520f1d20935fe44c7782f718
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.3 Windows/10
|
Release files / tailrec-0.1.6-py3-none-any.whl
| Download URL | tailrec-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f51c36117c72b75f6062233860d340ca9382a09a6ff22b4abef4625f2b0821d2
|
|
BLAKE2b-256 checksum How to use checksums |
895679d89e68a91f10876b143076ed4457a56547c83ebab39ee0e6fe84356cd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.3 Windows/10
|
Security for tailrec 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.