Given a list of filenames, we want to rename all the files with extension hpp to the extension h. To do this, we would like to generate a new list called newfilenames, consisting of the new filename. Using list comprehension#
filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]
newfilenames = [filename[:len(filename) - 3] + "h" for filename in filenames if filename.endswith("p")]
print(newfilenames)
output came ["stdio.h", "sample.h", "math.h"]
Should be ["program.c", "stdio.h", "sample.h", "a.out", "math.h", "hpp.out"]
I think you need