Replace Letters with numbers, but keep numbers

Hi,

Question;

I would like to ‘Translate’ all Letter characters to numbers, like;

A = 0
B = 1
C = 2
etc

But, If the input is/are already a number --> simply keep this number.
0 = 0
1 = 1
2 = 2

etc.

I have found a python component which ‘Translates’ the Letters into numbers correctly.
However, when I input an number There is an error.

Unfortunately I am not an python expert.
Any suggestion on how this could be done in python (e.g. using a try except statement)?

image

2020-10-26 Translate Letters into numbers but keep numbers.gh (8.6 KB)

thanks


Replace Letters with numbers, but keep numbers.gh (5.8 KB)

If you need it, force the input to be upper case and fill the ABC list.

Hi @ruud.vanknippenberg,

With a small change, your Python will work:

2020-10-26 Translate Letters into numbers but keep numbers v2.gh (7.3 KB)

Regards
Jeremy

2 Likes