newfilenames=[newfilenames.replace('hpp','h')for newfilenames in filenames] print(newfilenames)
Asked
Active
Viewed 5,914 times
0
-
you're appending a string there. You create a tuple by using brackets like so: `newfilenames.append((old_name, new_name))`. Check the answer of @OD1995 – wullxz Feb 03 '20 at 15:04
1 Answers
1
Try this:
filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]
newfilenames = []
for x in range(len(filenames)):
old_name = filenames[x]
if old_name.endswith(".hpp"):
new_name = old_name.replace('.hpp','.h')
else:
new_name = old_name;
newfilenames.append((old_name, new_name))
print (newfilenames)
-
this will also rename `hpp.out` to `h.out`. You need to check for `.hpp` at the end of the name. – wullxz Feb 03 '20 at 15:00
-
-
1
-
-