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.4.0.tar.gz (40.7 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.4.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: abbrev-1.4.0.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.4.0.tar.gz
Algorithm Hash digest
SHA256 513f95cffd1aa09a3a936d7f0bf237284e5ab65fe3f5031974f2d19701a428ca
MD5 af2ed76f61abb59f8a4e013f85f5a7b8
BLAKE2b-256 10fefd09925698f5edb63728f46fd12a0b34d5eb97e086b2f987d3a7f35f5ce6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: abbrev-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cb804bdf4ee63a0eb6fc1cf51b6029db6c90365c481b901cb98c16b231106a3
MD5 f8dd3d0bc5c8aaa8a251931f5ca37b71
BLAKE2b-256 eeb82d2ab5eaba55bc7837baa6d109138da1ff4f12d590fed8f4ef9b14c501b2

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