반응형
Consider the word "abode". We can see that the letter a is in position 1 and b is in position 2. In the alphabet, a and b are also in positions 1 and 2. Notice also that d and e in abode occupy the positions they would occupy in the alphabet, which are positions 4 and 5.
Given an array of words, return an array of the number of letters that occupy their positions in the alphabet for each word. For example,
solve(["abode","ABc","xyzD"]) = [4, 3, 1]
See test cases for more examples.
Input will consist of alphabet characters, both uppercase and lowercase. No spaces.
Good luck!
If you like this Kata, please try:
Solution:
def solve(arr):
alphabet = "abcdefghijklmnopqrstuvwxyz"
return [sum(int(a == b) for a, b in zip(i.lower(), alphabet)) for i in arr]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0122. The Feast of Many Beasts (0) | 2023.01.23 |
---|---|
0121. esreveR (0) | 2023.01.21 |
0119. Thinkful - Number Drills: Blue and red marbles (0) | 2023.01.19 |
0118. Ordered Count of Characters (0) | 2023.01.18 |
0117. get character from ASCII Value (0) | 2023.01.18 |