Skip to main content

🐜 Expand abbreviations 🐜

Project description

🐜 abbrev: Expand abbreviations 🐜

Expand a Sequence or Mapping of string abbreviations.

Handy when the user has a choice of commands with long names.

Example 1: Use a list of choices

import abbrev

a = ['one', 'two', 'three']

assert abbrev(a, 'one') == 'one'
assert abbrev(a, 'o') == 'one'
assert abbrev(a, 'tw') == 'two'

abbrev(a, 'four')  # Raises a KeyError: no such key
abbrev(a, 't')  # Raises a KeyError: ambiguous key ('two' or 'three'?)

Example 2: Use a dictionary of choices

import abbrev

d = {'one': 100, 'two': 200, 'three': 300}

assert abbrev(d, 'one') == 100
assert abbrev(d, 'o') == 100
assert abbrev(d, 'tw') == 200

Example 3: Make an abbreviator to re-use

import abbrev

d = {'one': 100, 'two': 200, 'three': 300}

abbreviator = abbrev(d)

assert abbreviator('one') == my_abbrevs('o') == 100
assert abbreviator('tw') == 200

Example 4: Get all matches, when multi=True

import abbrev

a = ['one', 'two, 'three'}

multi = abbrev(a, multi=True)  # Make an abbreviator

assert multi('t') == abbrev(d, 't', multi=True) == ('two', three')
assert multi('o') == abbrev(d, 'o', multi=True) == ('one', )

multi('four')  # Still raises a key error

Example 5: Get only the first result, when unique=False

import abbrev

d = {'one': 100, 'two': 200, 'three': 300}

assert abbrev(d, 't', unique=False) == (200, 300)

API Documentation

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

abbrev-1.3.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

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

abbrev-1.3.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file abbrev-1.3.0.tar.gz.

File metadata

  • Download URL: abbrev-1.3.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abbrev-1.3.0.tar.gz
Algorithm Hash digest
SHA256 c75c106c06a3bc79cf6ca05dd8ea5e3f8b43f9221f89aae82ebf9156d1a6e36a
MD5 a4e9e9e5616ddb42e1654dd04efe1630
BLAKE2b-256 2cada36398f48b9f48e34decf1ea0dffe1a0548ee2febc0145836ba058f03b1f

See more details on using hashes here.

File details

Details for the file abbrev-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: abbrev-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for abbrev-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c17b87890c23ab18550fff4ff9b8ebc16d7fbdb31e090e9fb67dc172d803f9de
MD5 971f8ce0512b2207400cbf760c0712d9
BLAKE2b-256 2a34b39e08b8a1f46c4b7173ecd856bae50ab18d5829d720923cdfa407afeda8

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