How can I replace the vowels of a word with underscores in python?
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p>

<p>So far this is what I have come up with and it just doesn't work</p>

<pre><code>word = input("Enter a word: ")
new_word = ""
vowels = "aeiouy"


for letter in word:
    if letter != vowels:
        new_word += word
    else:
       new_word += "_"
       print(new_word)
</code></pre>

<p>Using a list comprehension and setting <code>vowels</code> as a <code>set</code> object (this is really only valuable for speeding up performance if you have a large list of words over which you're iterating):</p>

<pre><code>&gt;&gt;&gt; vowels = set("aeiouy")
&gt;&gt;&gt; word = 'ampersand'
&gt;&gt;&gt; new_word = "".join([letter if letter not in vowels else "_" for letter in word])
&gt;&gt;&gt; print(new_word)
_mp_rs_nd
</code></pre>

python