def dial(t, spacer, wrap, obj): if t: unit = [m[len(t):] for m in obj if m.startswith(t)] if len(obj) == 1: return obj[t] if len(t) >= 5: return spacer + wrap + obj[t] + wrap elif len(t) >= 5 and re.search('\.', t): return spacer + wrap + str( obj[re.split('\.', txt, 1)[0]][int(re.split('\.', txt, 1)[1])]) + wrap