Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Convert Letters to Numbers in Python Using list comprehension

Convert Letters to Numbers in Python using list comprehension
text = "itsmycode"

# elegant way using list comprehension
num_list = [ord(x) - 96 for x in text]

# print the converted letters as numbers in list
print("After converting letters to numbers", num_list)
Comment

PREVIOUS NEXT
Code Example
Python :: # filter a list 
Python :: KeyError: 0 
Python :: get dataframe deminsions 
Python :: pairplot markersize 
Python :: python nmap api functionality 
Python :: load shapefile fiona multiline intersection 
Python :: number of libraries in python 
Python :: xgb model prediction changes if i save and load the model 
Python :: unittest run one test 
Python :: range function without end value 
Python :: open in new tab selenium python 
Python :: Code Example of Comparing None with empty string 
Python :: Add OR Concatenation of Tuples in python 
Python :: extract tables from image python 
Python :: python print numbers with commas 
Python :: unique lits on python 
Python :: how to move mouse by detected face and eye using opencv 
Python :: dict keys in tcl 
Python :: Loading data from Oracle Database to pandas DataFrames 
Python :: Python NumPy atleast_3d Function Example when inputs are high dimesion 
Python :: how to change the color of console output in python to green 
Python :: Python NumPy asanyarray Function Example List to an array 
Python :: Python NumPy array_split Function Example 01 
Python :: python os.listdir attributes 
Python :: __le__ 
Python :: funcs_and_args for loop python 
Python :: pymenu template 
Python :: simple tower of hanoi project python with gui 
Python :: Remove Brackets from List Using String Slicing method 
Python :: beautifulsoup - extracting link, text, and title within child div 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =