okay I tried to make a reverse of finding the num value of a letter bu it returns in an error :f

Traceback (most recent call last):
File "/home/darragh/Bureaublad/t.py", line 15, in <module>
numtolet('A')
File "/home/darragh/Bureaublad/t.py", line 6, in numtolet
letters
TypeError: list indices must be integers, not tuple

def numtolet(num):
	letters['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
	nummers = []
	for i in range(1,25):
		nummers.append(i)
	pos = nummers.find(num)
	poss = letters.find(pos - 1)
	return poss

You mean something like this?

def numtolet(num):
    letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
    return letters[num]

>>> numtolet(1)
'B'
>>> numtolet(14)
'O'

Or what about using chr() and then just adding 65?:

>>> def numtolet(num):
...     return chr(num + 65)
...     
>>> numtolet(1)
'B'
>>> numtolet(12)
'M'
>>> numtolet(14)
'O'
>>>

Or the reverse:

>>> def lettonum(let):
...     return ord(let) - 65
...     
>>> lettonum('O')
14
>>> lettonum('A')
0
>>> lettonum('N')
13
>>>

This will also trap number exceeding the index:

import string

def numtolet(num):
    if num > 25: return
    return string.ascii_uppercase[num]

print( numtolet(0) )   # A
print( numtolet(5) )   # F
print( numtolet(25) )  # Z
print( numtolet(26) )  # None
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.