我在做Count Vowel Strings in Ranges - LeetCode,下面是我的答案。
class Solution:
def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:
acc_arr = list(accumulate(words, lambda acc, word: acc + (word[0] in 'aeiou' and word[-1] in 'aeiou'), initial=0))
res = []
for l, r in queries:
res.append(acc_arr[r + 1] - acc_arr[l])
return res
我觉得 word[0] in 'aeiou' and word[-1] in 'aeiou'不够优雅,有没有好的写法?