How to convert letters to numbers using python -


i want convert letters numbers along special characters , numbers remaining is.

code:

input = raw_input('insert string: '); output = []; character in input:     number = ord(character) - 96;     output.append(number);  print output; 

i can convert alphabets letters, when input numbers, it's showing negative numbers.

enter image description here

any suggestions? in advance!

i guessing code using , other link gave in question -

print [ord(char) - 96 char in raw_input('write text: ').lower()] 

this , found out in example, convert characters unicode counterparts,if not want want convert numbers can use following -

>>> print ''.join([str(ord(ch) - 96) if ch.isalpha() else ch ch in raw_input('write text: ').lower()]) write text: abcd123 @!#as1 1234123 @!#1191 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -