I'm trying to store the vowels and constants indices of a string in two lists, so far I have the following:
def my_function(string):
vowels_index = [] # vowels indices list
const_index = [i if string[i] not in "AEIOU" else vowels_index.append(i) for i in range(len(string))] # constants indices list
Some None values are present in const_index:
>>> string = "BANANA"
>>> const_index = [i if string[i] not in "AEIOU" else vowels_index.append(i) for i in range(len(string))]
>>> const_index
[0, None, 2, None, 4, None]
>>>
Is there a better way to find the two lists?