def str_to_int(sentence, return_int=True):
    '''Returns spelled-out numbers as integers.
return_int: Return an integer rather than a string.'''
    
    number_conv_table = {

        'negative' : '0',
        '' : '0',
        'and' : '0',
        'dollars' : '0',
        'dollar' : '0',
        'zero' : '0',
        'one' : '1',
        'two' : '2',
        'three' : '3',
        'four' : '4',
        'five' : '5',
        'six' : '6',
        'seven' : '7',
        'eight' : '8',
        'nine' : '9',
        'ten' : '10',
        'eleven' : '11',
        'twelve' : '12',
        'thirteen' : '13',
        'fourteen' : '14',
        'fifteen' : '15',
        'sixteen' : '16',
        'seventeen' : '17',
        'eighteen' : '18',
        'nineteen' : '19',
        'twenty' : '20',
        'thirty' : '30',
        'forty' : '40',
        'fifty' : '50',
        'sixty' : '60',
        'seventy' : '70',
        'eighty' : '80',
        'ninety' : '90',
        'hundred' : '00', #sub flag
        'thousand' : '000', #flag
        'k' : '000', #flag
        'grand' : '000', #flag
        'million' : '000000', #flag
        'billion' : '000000000', #flag
        'trillion' : '000000000000', #flag
        'quadrillion' : '000000000000000', #flag
        'quintillion' : '000000000000000000', #flag
        'sextillion' : '000000000000000000000', #flag
        'septillion' : '000000000000000000000000', #flag
        'octillion' : '000000000000000000000000000', #flag
        'nonillion' : '000000000000000000000000000000', #flag
        'decillion' : '000000000000000000000000000000000', #flag
        'undecillion' : '000000000000000000000000000000000000', #flag
        'duodecillion' : '000000000000000000000000000000000000000', #flag
        'tredecillion' : '000000000000000000000000000000000000000000', #flag
        'quattuordecillion' : '000000000000000000000000000000000000000000000',
        }#flag

    flags = ['hundred', 'thousand', 'grand', 'million', 'billion', 'trillion',
             'quadrillion', 'quintillion','sextillion', 'septillion', 'octillion',
             'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion',
             'quattuordecillion', 'k']
    sub_flags = ['hundred']

    output = 0
    section = 0
    sections = []
    hundred_flag = False #detected value 'hundred'
    negative_flag = False #detected value 'negative'
    currency_flag = False #detected value 'dollar'
    
    sentence = sentence.replace('-', ' ').split(' ') #allow spaces and hyphens
    lowered_sentence = []
    
    for i in sentence:
        lowered_sentence.append(i.lower())
        
    sentence = lowered_sentence #create list of words in lowercase

    for word in sentence:
        sum_flag = True

        if word in ['point', 'dot']:
            raise FloatingPointError('Sentence must represent an integer.')
        
        while True:
            try:
                number = number_conv_table[word]
                if word == 'negative': #detect negative
                    negative_flag = True
                if word in ['dollar', 'dollars', 'k']:
                    currency_flag = True
                    if return_int:
                        input('\nNOTICE: Currency will be represented as a string not an integer. *press enter*')
                        print()
                    return_int = False
                break
            except KeyError:
                ref = word
                print('\nWARNING:',word,'is not a valid key. Please replace it.')
                word = str(input('Modify word: '))
                print()

        if word in flags: #merge if word is a flagged word
            section = str(section)
            section += number
            if word in sub_flags: #do not yet append number
                hundred_flag = True
            
        else:
            section = int(section) + int(number)

        if word in flags and hundred_flag == False: #finalize section and append to list
            sections.append(int(section))
            section = 0

        hundred_flag = False #reset flag

    sections.append(int(section))

    output = sum(sections)

    if negative_flag:
        output = 0 - output

    if currency_flag:
        output = format(output,',d')
        return '$'+output

    if not return_int:
        return format(output,',d')

    else:
        return output
Returns spelled-out numbers as integers.
return_int: Return an integer rather than a string.
recipes/Python/580679_Convert_Spelled_out_Integers_eg_three_thoustwo/recipe-580679.py