Last active
December 2, 2021 01:00
-
-
Save Codehunter-py/ef5872f4f2633ea66723df916506ef7c to your computer and use it in GitHub Desktop.
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 filenames. Fill in the blanks in the code using any of the methods you’ve learned thus far, like a for loop or a list comprehension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"] | |
# Generate newfilenames as a list containing the new filenames | |
# using as many lines of code as your chosen method requires. | |
newfilenames = [x.replace('.hpp','.h') for x in filenames] | |
print(newfilenames) | |
# Should be ["program.c", "stdio.h", "sample.h", "a.out", "math.h", "hpp.out"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment