-5

If I have a list with the entire alphabet in it, and I have a random letter, how can I figure out which number of the list has the letter, with "a" being 0 and "z" being 25?

import random
#            0    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
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

letter = random.choice(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"])

If the letter was, for example, b, how do I get the computer to know that the number is 1?

0 Answers0