Create a function that transforms any positive number to a string representing the number in words.  The function should work for all numbers between 0 and 999999.

### Examples

```
number2words(0)  ==>  "zero"
number2words(1)  ==>  "one"
number2words(9)  ==>  "nine"
number2words(10)  ==>  "ten"
number2words(17)  ==>  "seventeen"
number2words(20)  ==>  "twenty"
number2words(21)  ==>  "twenty-one"
number2words(45)  ==>  "forty-five"
number2words(80)  ==>  "eighty"
number2words(99)  ==>  "ninety-nine"
number2words(100)  ==>  "one hundred"
number2words(301)  ==>  "three hundred one"
number2words(799)  ==>  "seven hundred ninety-nine"
number2words(800)  ==>  "eight hundred"
number2words(950)  ==>  "nine hundred fifty"
number2words(1000)  ==>  "one thousand"
number2words(1002)  ==>  "one thousand two"
number2words(3051)  ==>  "three thousand fifty-one"
number2words(7200)  ==>  "seven thousand two hundred"
number2words(7219)  ==>  "seven thousand two hundred nineteen"
number2words(8330)  ==>  "eight thousand three hundred thirty"
number2words(99999)  ==>  "ninety-nine thousand nine hundred ninety-nine"
number2words(888888)  ==>  "eight hundred eighty-eight thousand eight hundred eighty-eight"
```

Difficulty: introductory

Starter code:

def number2words(n):
	

Solutions:
words = "zero one two three four five six seven eight nine" + \
" ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty" + \
" thirty forty fifty sixty seventy eighty ninety"
words = words.split(" ")

def number2words(n):
    if n < 20:
        return words[n]
    elif n < 100:
        return words[18 + n // 10] + ('' if n % 10 == 0 else '-' + words[n % 10])
    elif n < 1000:
        return number2words(n // 100) + " hundred" + (' ' + number2words(n % 100) if n % 100 > 0 else '')
    elif n < 1000000:
        return number2words(n // 1000) + " thousand" + (' ' + number2words(n % 1000) if n % 1000 > 0 else '')

d={0:'zero',1:'one',2:'two',3:'three',4:'four',5:'five',
6:'six',7:'seven',8:'eight',9:'nine',10:'ten',
11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'fifteen',
16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',
20:'twenty',30:'thirty',40:'forty',50:'fifty',
60:'sixty',70:'seventy',80:'eighty',90:'ninety',
100:'hundred',1000:'thousand'}
def number2words(n):
    """ works for numbers between 0 and 999999 """
    if 0<=n<=20:return d[n]
    if 20<n<=99 and n%10:return d[10*(n//10)]+'-'+d[n%10]
    if 20<n<99:return d[10*(n//10)]
    if n<1000 and n%100==0:return d[n//100]+' '+d[100]
    if 100<n<=999:return d[n//100]+' '+d[100]+' '+number2words(n%100)
    if n%1000==0:return d[n//1000]+' '+d[1000]
    return number2words(n//1000)+' '+d[1000]+' '+number2words(n%1000)

def number2words(n):
    """ works for numbers between 0 and 999999 """
    b=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
    b2=["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
    if 0 <= n <= 19:
        return b[n]
    elif 20 <= n <= 99:
        return "{}{}".format(b2[int(str(n)[0])-2],"" if int(str(n)[1]) == 0 else "-" + number2words(int(str(n)[1])))
    elif 100 <= n <= 999:
        return "{}{}".format(number2words(int(str(n)[0])) + " hundred","" if int(str(n)[1:]) == 0 else " " + number2words(int(str(n)[1:])))
    else:
        return "{}{}".format(number2words(int(str(n)[:-3])) + " thousand","" if int(str(n)[-3:]) == 0 else " " + number2words(int(str(n)[-3:])))

UNITS = ' one two three four five six seven eight nine ten '\
        'eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split(' ')
TENS  = ' ten twenty thirty forty fifty sixty seventy eighty ninety'.split(' ')
UNITS += [TENS[n//10] + '-' + UNITS[n%10] if n%10 else TENS[n//10] for n in range(20, 100)]

def number2words(n):
    if n == 0:
        return 'zero'
    
    text = []
    
    if n >= 1000:
        text.append(number2words(n//1000) + ' thousand')
        n %= 1000
    
    hundred, unit = divmod(n, 100)
    if hundred:
        text.append(UNITS[hundred] + ' hundred')
    if unit:
        text.append(UNITS[unit])
    
    return ' '.join(text)

def number2words(n):
    if n == 0: return "zero"
    if n == 10: return "ten"
    
    numbers_11_19={
    "0":"ten",
    "1":"eleven",
    "2":"twelve",
    "3":"thirteen",
    "4":"fourteen",
    "5": "fifteen",
    "6":"sixteen",
    "7":"seventeen",
    "8":"eighteen",
    "9":"nineteen"
    }
    numbers_1_9={
    "0":"",
    '1':'one',
    '2':'two',
    "3":"three",
    "4":"four",
    "5":"five",
    "6":"six",
    "7":"seven",
    "8":"eight",
    "9":"nine",
    }
    numbers_20_100={
    "0":"",
    "2":"twenty",
    "3":"thirty",
    "4":"forty",
    "5":"fifty",
    "6":"sixty",
    "7":"seventy",
    "8":"eighty",
    "9":"ninety",
    }
  
    nStr=str(n)
    print (nStr)
    s=""
    L=len(nStr)
    pos=0
    if pos==L-6:#4 simvol sotni tisyzcg
        s+=numbers_1_9.get(nStr[pos])
        if nStr[pos]!="0":s+=" hundred "
        pos+=1
    if pos==L-5:#4simvol - desytki ticych
        if nStr[pos]=="1": #11 - 19
            s+=numbers_11_19.get(nStr[pos+1])
            pos=+1
        else:
            s+=numbers_20_100.get(nStr[pos])
            if nStr[pos+1]!="0" and nStr[pos]!="0" : s+="-"
        pos+=1
    if pos==L-4:#3 simvol - tisycha
        if nStr[pos-1]!="1": s+=numbers_1_9.get(nStr[pos])
        s+=" thousand "
        pos+=1
    if pos==L-3:#2 simbol - sotka
        s+=numbers_1_9.get(nStr[pos])
        if nStr[pos]!="0":s+=" hundred "
        pos+=1
    if pos==L-2: #1 simvol, desytok
        if nStr[pos]=="1": #11 - 19
            s+=numbers_11_19.get(nStr[pos+1])
            pos=-1
        else:
            s+=numbers_20_100.get(nStr[pos])
            if nStr[pos+1]!="0" and nStr[pos]!="0" : s+="-"
        pos+=1
    if pos==L-1: #0 simvol, edinici
        s+=numbers_1_9.get(nStr[pos]) 
    return s.strip()

nums = ["zero", "one", "two", "three", "four", "five", 
        "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
        "thirteen", "fourteen", "fifteen", "sixteen",
        "seventeen", "eighteen", "nineteen"]
        
tens = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]



def number2words(n):
    if n < 20:
        return nums[n]
    if n < 100:
        nn = (n-20)%10
        return "%s%s" % (tens[int((n-20)/10)], ("-"+nums[nn] if nn else ""))
    if n < 1000:
        nh = int(n / 100)
        nt = n % 100
        return ("%s hundred %s" % (number2words(nh), number2words(nt) if nt else "")).strip()
    nto = int(n / 1000)
    nh = n % 1000
    return ("%s thousand %s" % (number2words(nto), number2words(nh) if nh else "")).strip()
        


d = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five',
     6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten',
     11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen',
     15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 
     19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 
     50: 'fifty', 60: 'sixty', 70: 'seventy', 80: 'eighty', 
     90: 'ninety', 0:''}

def number2words(n):   
    s = (htu(n // 1000) + ' thousand ' if n // 1000 else '') + htu(n % 1000)
        
    return ' '.join(s.split()) if s else 'zero'

    
def htu(n):
    h, tu, u = n//100, n % 100, n % 10
    t = (d[tu] if tu in d else d[tu//10*10] + '-' + d[u]).strip('-')
    return d[h] + ' hundred ' + t if h else t

base = ' thousand million billion trillion quadrillion quintillion sextillion septillion'.split(' ')
ALL = {int(i):x for i,x in zip('0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 10 20 30 40 50 60 70 80 90 100'.split(),'zero one two three four five six seven eight nine eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen ten twenty thirty forty fifty sixty seventy eighty ninety'.split(' ')+['one hundred'])}
parse=lambda n:(ALL.get(n,ALL[n//10*10]+'-'+ALL[n%10] if n<100 else ALL[n//100]+' hundred '+parse(n%100)).strip()) if n else ''
number2words=lambda n:' '.join([parse(int(i))+' '+j if int(i) else '' for i,j in zip(format(n, ',').split(',')[::-1], base)][::-1]).strip() or 'zero'  # SUPPORT UPTO SEPTILLION...

special = {
    '0': 'zero',
    '1': 'one',
    '2': 'two',
    '3': 'three',
    '4': 'four',
    '5': 'five',
    '6': 'six',
    '7': 'seven',
    '8': 'eight',
    '9': 'nine',
    '10': 'ten',
    '11': 'eleven',
    '12': 'twelve',
    '13': 'thirteen',
    '14': 'fourteen',
    '15': 'fifteen',
    '16': 'sixteen',
    '17': 'seventeen',
    '18': 'eighteen',
    '19': 'nineteen',
    '20': 'twenty',
    '30': 'thirty',
    '40': 'forty',
    '50': 'fifty',
    '60': 'sixty',
    '70': 'seventy',
    '80': 'eighty',
    '90': 'ninety'
}
def three_digits2words(s):
    ''' len of s should <= 3 '''
    s = str(int(s)) # remove leading 0s
    if s in special:
        return special[s]
    if len(s) == 2:
        return '{}-{}'.format(special[s[0]+'0'], special[s[1]])
    else:
        lower2 = three_digits2words(s[1:])
        return '{} hundred'.format(special[s[0]]) + ((" " + lower2) if lower2 != 'zero' else '')

def number2words(n):
    """ works for numbers between 0 and 999999 """
    s = str(n)
    lower3 = three_digits2words(s[-3:])
    if len(s) > 3:
        return "{} thousand".format(three_digits2words(s[:-3])) + ((" " + lower3) if lower3 != 'zero' else '')
    else:
        return lower3

X = ("zero", "one", "two", "three", "four",
     "five", "six", "seven", "eight", "nine",
     "ten", "eleven", "twelve", "thirteen", "fourteen",
     "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
Y = (None, None, "twenty", "thirty", "forty",
     "fifty", "sixty", "seventy", "eighty", "ninety")


def number2words(n):
    if n < 20: return X[n]
    if n < 100: return f"{Y[n//10]}-{X[n%10]}" if n%10 else Y[n//10]
    if n < 1000: return f"{X[n//100]} hundred{f' {number2words(n%100)}' if n%100 else ''}"
    return f"{number2words(n//1000)} thousand{f' {number2words(n%1000)}' if n%1000 else ''}"