擅长:python、mysql、java
<pre><code>filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]
changed_filenames = []
# loop over all the filenames
for filename in filenames:
# does this file name end in .hpp ?
if filename.endswith(".hpp"):
# make a new filename, omitting the final two characters
filename = filename[:-2]
# append the filename to the new list
changed_filenames.append(filename)
</code></pre>