擅长:python、mysql、java
<p>这可以简化为<code>isalpha()</code>使用下划线代替字母,否则保留标点符号</p>
<pre><code>lines = ["All Star-Smash Mouth", "Don't Stop Believin'-Journey", "Mr. Brightside-The Killers"]
song = random.choice(lines)
name, artist = song.split('-')
s = ''
for word in name.split():
s += word[0] + ' '.join('_' if l.isalpha() else l for l in word[1:]) + ' /'
print(s[:-1] + ' By ' + artist)
</code></pre>