I have a string like this:
word = 'python'
Based on string.ascii_lowercase, I'd like to create a new array which looks like this:
[15, 24, 19, 7, 14, 13]
My solution for this problem was to do the following:
alphabet = {char: i for i, char in enumerate(string.ascii_lowercase)}
indices = [alphabet[char] for char in word]
print(indices)
Output: [15, 24, 19, 7, 14, 13]
But I'm looking for a more efficient way, without using loops. How can I do that in a vectorized way?