# vowel finder, error: list index out of range

• Last Update :
• Techknowledgy :

You can try something like this:

```vowels = 'aeiou'
string = input('Input string > ')
vow_in_str = []

for char in string:
if char in vowels:
vow_in_str.append(char)

print(vow_in_str)```

Here's a much faster one:

```z = ['a', 'e', 'i', 'o', 'u']

n = input('Input string: ')

m = [x
for x in n
if x in z
]

print(m)```

No need for that double loop, they take too long once you get into bigger lists.

```>>> Input string: hello >>>
['e', 'o']```

The code can be modified as follow:

```  for i in z:
for j in a:
if i == j: #
try to match letter by letter
print('vowel found')
m.append(i)
else:
continue```

st = "Nice day"

```z = ['a', 'e', 'i', 'o', 'u']
# convert st to list of chars
y = [ch.lower() for ch in st
if ch != ' '
]

# convert both list to sets and find the lenght of intersection
print(len(set(z) & set(y)))

3```

Suggestion : 2

I suggest you ignore lists and instead do something like this: result = "" and you add the elements, if they’re not a vowel.,def anti_vowel(text): an_vo = “” for i in text: if i not in “aeiouAEIOU”: an_vo += i return an_vo,As for what happens in your case (I replaced range with its result for demonstration purposes), here’s an analoguous example:,It returns a “String index out of range” error. Can someone help me out ?

This is my code for the anti-vowel problem :

```def anti_vowel(string):
my_list = list(string)
for i in range(0, len(my_list) - 1):
if my_list[i] in "aeiouAEIOU":
my_list = my_list.pop(i)
return my_list```

As for what happens in your case (I replaced `range` with its result for demonstration purposes), here’s an analoguous example:

```my_list = ['a', 'b', 'c']
for i in [0, 1, 2]:
my_list = my_list.pop(i)

in the first iteration, i = 0
my_list = my_list.pop(0)
-- > my_list == ['b', 'c']

-- > next iteration, i = 1
my_list = my_list.pop(1)
-- > my_list == ['b']

-- > next iteration, i = 2
my_list = my_list.pop(2)
-- > error, there 's no element with index 2!```

I suggest you ignore lists and instead do something like this: `result = ""` and you add the elements, if they’re not a vowel.

```def anti_vowel(string):
result = ""
for c in string:
if c.lower() not in "aeiou":
result += c
return result```

Suggestion : 3

The index() method returns the index of the specified element in the tuple.,In the above example, we have used the index() method to find the index of a specified element in the vowels tuple.,The element 'e' appears in index 1 in the vowels tuple. Hence, the method returns 1.,In the above example, we have used the index() method to find the index of an element that is not present in the numbers tuple.

### Example

```# tuple containing vowels
vowels = ('a', 'e', 'i', 'o', 'u')

# index of 'e' in vowels
index = vowels.index('e')

print(index)

# Output: 1```

### Example

```# tuple containing vowels
vowels = ('a', 'e', 'i', 'o', 'u')

# index of 'e' in vowels
index = vowels.index('e')

print(index)

# Output: 1```

The syntax of the `index()` method is:

`tuple.index(element, start_index, end_index)`

## Example 1: Python Tuple index()

```# tuple containing vowels
vowels = ('a', 'e', 'i', 'o', 'i', 'u')

# index of 'e' in vowels
index = vowels.index('e')

print('Index of e:', index)

# index of the first 'i'
is returned
index = vowels.index('i')

print('Index of i:', index)```

## Example 2: index() throws an error if the specified element is absent in the Tuple

```# tuple containing numbers
numbers = (0, 2, 4, 6, 8, 10)

# throws error since 3 is absent in the tuple
index = numbers.index(3)

print('Index of 3:', index)```

## Example 3: index() With Start and End Parameters

```# alphabets tuple
alphabets = ('a', 'e', 'i', 'o', 'g', 'l', 'i', 'u')

# returns the index of first 'i' in alphabets
index = alphabets.index('i')

print('Index of i in alphabets:', index)

# scans 'i'
from index 4 to 7 and returns its index
index = alphabets.index('i', 4, 7)

print('Index of i in alphabets from index 4 to 7:', index)```

Suggestion : 4

That won’t work. It causes the runtime error IndexError: list index out of range. The reason is that len(seq) returns the number of elements in the list, 16, but there is no element at index position 16 in seq.,You probably expected to see 'b', but computer scientists typically start counting from zero, not one. Think of the index as the numbers on a ruler measuring how many elements you have moved into the sequence from the beginning. Both rulers and indices start at 0.,Using slices to delete list elements can be awkward, and therefore error-prone. Python provides an alternative that is more readable.,A data type that contains a sequence of elements of any type, like a list, but is immutable. Tuples can be used wherever an immutable type is required, such as a key in a dictionary (see next chapter).

```[10, 20, 30, 40, 50]
["spam", "bungee", "swallow"]
(2, 4, 6, 8)
("two", "four", "six", "eight")[("cheese", "queso"), ("red", "rojo"), ("school", "escuela")]```
```>>> thing = 2, 4, 6, 8
>>> type(thing)
<class 'tuple'>
>>> thing
(2, 4, 6, 8)```
```>>> singleton = (2,)
>>> type(singleton)
<class 'tuple'>
>>> not_tuple = (2)
>>> type(not_tuple)
<class 'int'>
>>> empty_tuple = ()
>>> type(empty_tuple)
<class 'tuple'>```
```>>> fruit = "banana" >>>
fruit
'a' >>>
fruits = ['apples', 'cherries', 'pears'] >>>
fruits
'apples' >>>
prices = (3.99, 6.00, 10.00, 5.25) >>>
prices
5.25
>>>
pairs = [('cheese', 'queso'), ('red', 'rojo'), ('school', 'escuela')] >>>
pairs
('school', 'escuela')```
```>>> len('banana')
6```
```>>> len(['a', 'b', 'c', 'd'])
4
>>>
len((2, 4, 6, 8, 10, 12))
6
>>>
pairs = [('cheese', 'queso'), ('red', 'rojo'), ('school', 'escuela')] >>>
len(pairs)
3```
{"ft_lang_label":"__label__en","ft_lang_prob":0.6317941,"math_prob":0.8333766,"size":5426,"snap":"2023-14-2023-23","text_gpt3_token_len":1634,"char_repetition_ratio":0.13021025,"word_repetition_ratio":0.1721225,"special_character_ratio":0.35182455,"punctuation_ratio":0.18245614,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9918382,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-27T07:14:06Z\",\"WARC-Record-ID\":\"<urn:uuid:e0ee07ba-ce33-4f2c-ad59-69fee5606a64>\",\"Content-Length\":\"59737\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:15f6aa74-0a33-4220-9f4e-9b02c5eef1bb>\",\"WARC-Concurrent-To\":\"<urn:uuid:c5bd59f8-3abc-4f77-949f-8d869275f066>\",\"WARC-IP-Address\":\"54.36.230.123\",\"WARC-Target-URI\":\"https://splunktool.com/vowel-finder-error-list-index-out-of-range\",\"WARC-Payload-Digest\":\"sha1:6PIYLLU5GAOIAHZGZM5DTWZALC2VR75D\",\"WARC-Block-Digest\":\"sha1:FVVL36PZVRZ675Z47AQZ6JIFJ44RKWFQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296948609.41_warc_CC-MAIN-20230327060940-20230327090940-00285.warc.gz\"}"}