Convert alphabet letters to number in Python

后端 未结 16 1799
慢半拍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:33

    >>> [str(ord(string.lower(c)) - ord('a') + 1) for c in string.letters]
    ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17',
    '18', '19', '20', '21', '22', '23', '24', '25', '26', '1', '2', '3', '4', '5', '6', '7', '8',
    '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24',
     '25', '26']
    

提交回复
热议问题