get_acronym

pyhelpers.text.get_acronym(text, only_capitals=False, capitals_in_words=False)[source]

Get an acronym (in capital letters) of an input text.

Parameters:
  • text (str) – any text

  • only_capitals (bool) – whether to include capital letters only, defaults to False

  • capitals_in_words (bool) – whether to include all captical letters in a single word, defaults to False

Returns:

acronym of the input str_var

Return type:

str

Examples:

>>> from pyhelpers.text import get_acronym

>>> text_a = 'This is an apple.'
>>> acron = get_acronym(text_a)
>>> acron
'TIAA'

>>> text_b = "I'm at the University of Birmingham."
>>> acron = get_acronym(text_b, only_capitals=True)
>>> acron
'IUB'

>>> text_c = 'There is a "ConnectionError"!'
>>> acron = get_acronym(text_c, capitals_in_words=True)
>>> acron
'TCE'