Search code examples
pythonpyspark

transforming a 7 digit integer number to unique alphanumeric value and vice versa


I am trying to convert a 7 digit integer to 6 character alphanumeric value (ALL CAPS a). I don't want to translate the integer value, is there any other way I can do it ? encode it and decode with output value back to the function and get in input back again -

Input Output
7200123 ABC123
ABC123 7200123
1234567 12X7S3
12X7S3 1234567

Ideally I should be able to pass any integer and get an encoded 6 character alphanumeric value and pass the 6 Character Alphanumeric value to get the integer back


Solution

  • so this is how I was able to perform it, not showing 6 char values though but trade off is acceptable for now. Based on lead from @jorg

    import base36
    
    print(base36.dumps(7200345))
    print(base36.loads("4abtl"))
    

    Output