Skip to main content

__ (Double Underscores, 2us)

PyPI version

Glueing functionals by import __ for python!

Install

The package is written in pure python, with no dependencies other than the Python language. Just do:

pip install 2us

Requires Python 3.5 or higher.

Why this?

Python is a great language for creating convenient wrappers around native code and implementing simple, human-friendly functions. In python, a bunch of builtin higher-order methods (which means that they accept functions as arguments) such as map, filter are available. They enable streamed data processing on containers that focus on the processing itself, in contrast with noisy code on traditional command-based languages that is heavily involved in loops.

However, you may occasionally run into the situatiion where you find that there is no standard library functions to implement in-line unpacking of tuples, adding all numbers in a list by a constant shift, so you will have to write:

map(lambda x: x + 1, some_list)
map(lambda x: x[0], some_list)

which seems rather dumb due to the inconvenient definition of lambda functions in python.

Using __

Start using the package by importing __:

import __

And then __ can be used to create convenient functions that are identical to those written with lambda. Examples:

assert sum(map(__ + 1, range(1000))) == sum(map(lambda x: x + 1, range(1000)))
assert set(map(__[0], {1: 2, 4: 6}.items())) == {1, 4}
assert functools.reduce(__ + __, range(1000)) == sum(range(1000))

Currently there is a drawback: python do not support overriding __contains__ returning non-boolean values, so the in condition should be handled separately.

assert tuple(map(__.is_in([1, 2]), [3, 1, 5, 0, 2])) == (False, True, False, False, True)
assert list(map(__.contains('1'), '13')) == [True, False]

Metadata

Release files for 2us 0.0.1.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for 2us 0.0.1.post1
File Size Uploaded
2us-0.0.1.post1.tar.gz 3.1 kB Details

Release files / 2us-0.0.1.post1.tar.gz

Download URL 2us-0.0.1.post1.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
98b482b9ac0651f093cdb5571ce12b8afaf83cd2caa2ef2984bc364352abdf4e
BLAKE2b-256 checksum
How to use checksums
ad9cb33a95aad023cb4d339e8a6c37ba9518990c5e82e34b245788baf6d2a75b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.0.1.post1 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page