I'm trying to rename text/num ids (eg. ABC123) to just num ids (eg. 123123) by matching text to a dictionary code. (just learning how to code, so if better idea, please do tell).
I tried searching for solutions but many are for using print. I need to pass the results to another function, so can't use print.
def convertid(old_id):
code = {'A' : '1','B' : '2','C' : '3','D' : '4','E' : '5','F' :
'6','G' : '7','H' : '8','I' : '9','J' : '10','K' : '11','L' :
'12','M' : '13','N' : '14','O' : '15','P' : '16','Q' : '17','R' :
'18','S' : '19','T' : '20','U' : '21','V' : '22','W' : '23','X' :
'24','Y' : '25','Z' : '26', '1' : '1','2' : '2','3' : '3','4' :
'4','5' : '5','6' : '6','7' : '7','8' : '8','9' : '9','0' : '0'}
for x in old_id:
new_id = code[x],end = ""
return new_id
I've also tried new_id = "".join(code[x])
,and new_id += code[x]
, but none of them work.
I was hoping to get "123123" as the new id in a single line, instead of:
1
2
3
1
2
3
on multiple lines (sorry, don't know why the preview is showing the numbers on double space lines. The result I got were in single space lines.).