docs: get_abbr
This commit is contained in:
parent
ed36873af4
commit
8156d24ec9
1 changed files with 10 additions and 0 deletions
|
|
@ -402,6 +402,16 @@ def today() -> str:
|
|||
|
||||
|
||||
def get_abbr(string: str, max_len: int = 2) -> str:
|
||||
"""Returns the abbreviation of the given string.
|
||||
|
||||
Examples:
|
||||
|
||||
* "John Doe" => "JD"
|
||||
* "Jenny Jane Doe" => "JJ" (default, `max_len` = 2)
|
||||
* "Jenny Jane Doe" => "JJD" (`max_len` = 3)
|
||||
|
||||
Returns "?" if the given string is empty.
|
||||
"""
|
||||
abbr = ""
|
||||
for part in string.split(" "):
|
||||
if len(abbr) < max_len and part:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue