Given the list of filenames, we want to rename all files with extension hpp to the extension h. To do this, we would like to generate the new list named newfilenames, consisting of a 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"]