擅长:python、mysql、java
<p>有更有效的方法来创建这样的dict:</p>
<pre><code>example = 'Accomodation'
VOWELS = 'aeiou'
CONSONANTS = 'bcdfghjklmnpqrstvwxyz'
replace_dict = {
**{v: 'v' for v in VOWELS},
**{V: 'V' for V in VOWELS.upper()},
**{c: 'c' for c in CONSONANTS}
}
print(''.join(replace_dict[s] for s in example))
# Vccvcvcvcvvc
</code></pre>