擅长:python、mysql、java
<p>只需尝试在列表中使用内置方法“replace”</p>
<pre><code>filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]
new = [name.replace(".hpp",".h") for name in filenes]
print(new)
>>> ["program.c", "stdio.h", "sample.h", "a.out", "math.hpp", "hpp.out"]
</code></pre>