The positions of all vowels in the string
<p>I am trying to write programs that reads a line of input as a string and print the positions of all vowels in the string.</p>

<pre><code>line = str(input("Enter a line of text: "))

vowels = ('a', 'e', 'i', 'o', 'u')
position = ""
for i in line :
    if i.lower() in vowels :
       position += ("%d ", i)
print("Positions of Vowels " + position)
</code></pre>

<p>Expected: <code>Positions of Vowels 1,3,4,5,</code></p>

<p>Gives me: <code>Positions of Vowels</code></p>

<p>What can I do?</p>

<p>If you want a list of indexes, the following should work using <code>enumerate</code>:</p>

<pre><code>&gt;&gt;&gt; text = 'hello world vowel'
&gt;&gt;&gt; vowels = 'aeiou'
&gt;&gt;&gt; [i for i, c in enumerate(text.lower()) if c in vowels]
[1, 4, 7, 13, 15]
</code></pre>

<p>For your comma formatting:</p>

<pre><code>&gt;&gt;&gt; ', '.join(str(i) for i, c in enumerate(text.lower()) if c in vowels)
'1, 4, 7, 13, 15'
</code></pre>

python string python-3.x