-2

I am working with a word which is input by the user. Example: "where". I need to find the first vowel and start the word from it, and place the beginning of the word to the end.

First I want to understand indexes of each letter and I did it with enumerate(): Now I want to get the index of a vowel and make the word sliced.

The question is how to pass to python the information about the indices I got from enumerate and how to make it define the index of the vowel?

I found lots of tutorials on slicing, but still did not get how to unite these two functions. Please help me (maybe you know a tutorial which can help or just give ideas). I am a beginner, so keep it simple, please. I am stuck, I don't understand how to iterate through the word/words and at the same time get its index.

DKzK
  • 1
  • 1
  • 1
    Please clarify by showing the output you expect and the problem you have with your current code (which you seem to have forgotten to post) – DarkKnight Feb 19 '23 at 08:03

3 Answers3

-1

You can use the following:

word = 'where'
i_vowel = 0
for index, char in enumerate(word):
    if char in "aeiou":
        i_vowel = index
        break
word = word[i_vowel:]+word[0:i_vowel]
pulkit
  • 47
  • 6
-1

Use enumerate to "walk" the string. This gives you the index (subscript) and character at the corresponding position. Then a simple slice will give the output you need.

VOWELS = set('aeiouAEIOU')

s = 'where'

for i, c in enumerate(s):
    if c in VOWELS:
        print(f'{s[i:]}{s[:i]}')
        break

Output:

erewh
DarkKnight
  • 19,739
  • 3
  • 6
  • 22
-1
word = 'where'
vowels = "aeiou"

for i, letter in enumerate(word):
    if letter in vowels:
        i_word = word[i:] + word[:i]
        break

print(i_word)