def wrap(text, indent=' ',
               initial_indent='',
               subsequent_indent='',
               drop_whitespace=True,
               replace_whitespace=True,
               width=70):
    '''Wrap text for a given line width'''

    from textwrap import wrap
    from textwrap import indent as textwrap_indent

    lindent = len(indent)

    return textwrap_indent('\n'.join(wrap(text,
                                          width=width-lindent,
                                          initial_indent=initial_indent,
                                          subsequent_indent=subsequent_indent,
                                          drop_whitespace=drop_whitespace,
                                          replace_whitespace=replace_whitespace)),
                            indent)


def printwrap(text, indent=' ',
                    width=70,
                    initial_indent='',
                    subsequent_indent='',
                    prepend_blanc_line=True,
                    drop_whitespace=True,
                    replace_whitespace=True):
    '''Wrap text for a given line width and print it'''

    from sys import stdout

    if prepend_blanc_line:
        print()

    print(wrap(text,
               indent=indent,
               width=width,
               initial_indent=initial_indent,
               subsequent_indent=subsequent_indent,
               drop_whitespace=drop_whitespace,
               replace_whitespace=replace_whitespace))

    stdout.flush()


def integer2english(i:int=0):
    '''Return the associated English expression for an index number, e.g., 1 => 1st'''

    selectcases = { 1: '1st',
                    2: '2nd',
                    3: '3rd',
                  }

    return selectcases.get(i%10, str(i)+'th')
