Advertisement
juanmartinvk

Python Crash Course: Week 4 Quiz ex. 1

Dec 25th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]
  2. newfilenames = []
  3. for filename in filenames:
  4.   if filename.endswith("hpp"):
  5.     newfilenames.append((filename, filename.replace("hpp", "h")))
  6.   else:
  7.     newfilenames.append((filename, filename))
  8.  
  9. print (newfilenames) # Should be [('program.c', 'program.c'), ('stdio.hpp', 'stdio.h'), ('sample.hpp', 'sample.h'), ('a.out', 'a.out'), ('math.hpp', 'math.h'), ('hpp.out', 'hpp.out')]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement