我已經完成了任務,但是以最基本的形式尋找縮短它的幫助,因此它可以應用於任何單詞而不僅僅是一個單詞有八個字母,這裏就是我有這麼遠(有點長爲它做什麼):Python:將單詞轉換爲字母列表,然後將字母索引與小寫字母對齊
alpha = map(chr, range(97, 123))
word = "computer"
word_list = list(word)
one = word[0]
two = word[1]
three = word[2]
four = word[3]
five = word[4]
six = word[5]
seven = word[6]
eight = word[7]
one_index = str(alpha.index(one))
two_index = str(alpha.index(two))
three_index = str(alpha.index(three))
four_index = str(alpha.index(four))
five_index = str(alpha.index(five))
six_index = str(alpha.index(six))
seven_index = str(alpha.index(seven))
eight_index = str(alpha.index(eight))
print (one + "=" + one_index)
print (two + "=" + two_index)
print (three + "=" + three_index)
print (four + "=" + four_index)
print (five + "=" + five_index)
print (six + "=" + six_index)
print (seven + "=" + seven_index)
print (eight + "=" + eight_index)
它找到字母每個字符的索引a - > 0,b - > 1,c - > 2,... z - > 25'。 –
使用'用於單詞中的字母:'(或'用於word_list中的字母') – furas