0

newfilenames=[newfilenames.replace('hpp','h')for newfilenames in filenames] print(newfilenames)

Binh Nguyen
  • 31
  • 1
  • 5
  • 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 Answers1

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)

enter image description here

Gautam
  • 3,707
  • 5
  • 36
  • 57
OD1995
  • 1,647
  • 4
  • 22
  • 52