나는 이렇게 학습한다/Algorithm & SQL

Find the vowels

daco2020 2022. 5. 1. 21:49
반응형

We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).

So given a string "super", we should return a list of [2, 4].

Some examples:
Mmmm  => []
Super => [2,4]
Apple => [1,5]
YoMama -> [1,2,4,6]

NOTES

  • Vowels in this context refers to: a e i o u y (including upper case)
  • This is indexed from [1..n] (not zero indexed!)

 

Solution:

1. Check the existence of vowels in a word.
2. If there is a collection, the index is returned in an array.

 

def vowel_indices(word):
    return [i+1 for i, v in enumerate(word) if v in 'aeiouyAEIOUY']

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Categorize New Member  (0) 2022.05.03
Are You Playing Banjo?  (0) 2022.05.02
Odd or Even?  (0) 2022.04.30
Sort array by string length  (0) 2022.04.29
Sum of odd numbers  (0) 2022.04.28