🐜 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
Release history Release notifications | RSS feed
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.2.1.tar.gz
(3.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file abbrev-1.2.1.tar.gz.
File metadata
- Download URL: abbrev-1.2.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fa3f0ab570f470b62cf9da1e5454daf3f046bd12990718aaf3d4b2f28c42bf4
|
|
| MD5 |
e5aee96bea4dc291a455e37dd7508c85
|
|
| BLAKE2b-256 |
7f9a20326277c558a83ef34803b7b4eb4ff1ab252d44dde4b6cc1786f0a240a1
|
File details
Details for the file abbrev-1.2.1-py3-none-any.whl.
File metadata
- Download URL: abbrev-1.2.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.11 Darwin/21.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab1ed783c8b98897946d46aa31ce0fee7c18dd7a52b4b413ef5ef964fbfe2b30
|
|
| MD5 |
faa41b42be602b6157153275abfe84c6
|
|
| BLAKE2b-256 |
56ab7081c4c1ad8fd06926e0d4bca279ecd5de48073d1de062f2fab89c17eb8b
|