Convert alphabet letters to number in Python

后端 未结 16 1796
慢半拍i
慢半拍i 2020-11-28 05:09

How can the following be finished?

characters = [\'a\'\'b\'\'c\'\'d\'\'e\'\'f\'\'g\'\'h\'\'i\'\'j\'\'k\'\'l\'\'m\'\'n\'\'o\'\'p\'\'q\'\'r\'\'t\'\'u\'\'v\'\'w         


        
16条回答
  •  温柔的废话
    2020-11-28 05:46

    You can map the alphabet to a list and return the index of each one as per the below :

    import string
    
    alphabet=string.ascii_lowercase
    #alphabet='abcdefghijklmnopqrstuvwxyz'
    
    #Get the character index , ex: e  
    print(chars.find('e'))
    #This will return 4
    

提交回复
热议问题