Next / Previous / Contents / Shipman's homepage

11.5. engDeComma(): Normalize an English name

Converts “Heron, Great Blue” to “Great Blue Heron”, for example.

abbr.py
# - - -   e n g D e C o m m a

def engDeComma ( eng ):
    '''Transform "GENERIC-PART, SPECIFIC-PART" to the normal order.
    '''
    #-- 1 --
    # [ if eng contains a comma ->
    #     commaPos  :=  its position
    #   else ->
    #     return eng ]
    commaPos = eng.find ( ',' )
    if commaPos < 0:
        return eng

    #-- 2 --
    return ( "%s %s" %
             (eng[commaPos+1:].strip(), eng[:commaPos]) )