filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"]我想用 .h 替换 .hpp。y=[]for x in filenames: if '.hpp' in x: x=x.replace('hpp','h') y.append(x) else: y.append(x)print(y)有没有更简单的方法来做到这一点?
添加回答
举报
0/150
提交
取消