Advertisement
rodrigosantosbr

[Py] Remove Brazilian Prepositions from Name

Jan 26th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. def remove_name_prepositions(name):
  2.     """returns a name without its prepositions
  3.  
  4.    Parameters
  5.    ----------
  6.        name: string
  7.            Full name
  8.  
  9.    Returns
  10.    -------
  11.        string
  12.  
  13.    Raises
  14.    ------
  15.        None
  16.  
  17.    Examples
  18.    --------
  19.        >>> nome = 'Dezêncio Feverêncio de Oitenta e Cinco'
  20.        >>> print(remove_name_prepositions(nome))
  21.        Dezêncio Feverêncio Oitenta Cinco
  22.  
  23.    See Also
  24.    --------
  25.        -
  26.    """
  27.     name = str(name)
  28.     prepositions = ("do","da","dos","das","de","di","du","e")
  29.     new_word = []
  30.     for token in name.split():
  31.         if token.lower() not in prepositions:
  32.             new_word.append(token)
  33.     return ' '.join(new_word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement