with open('/path/to/smi_path') as smi:
content = [
line.replace(target, replacement)
for target, replacement in filter_words
for line in smi.readlines()
]
with open('/path/to/destination', 'w') as f:
f.writelines(content)
# a 변수가 리스트라면 아래와 같이 하는게 파이썬 다운 코드
a = ['a', 'b', 'c', 'd']
for c in a:
print(c)
print(72*'-')
# range를 써서 index로 접근해도 되지만 위 코드가 더 깔끔한 표현
for i in range(len(a)):
print(a[i])
print(72*'-')
# 만약 a 변수가 리스트가 아니라 님 조건처럼 a0, a1, a3, a4 식이라면
# for로 접근하려면 문자열로 변수명을 연산한 후 eval를 써야 할 듯
a0 = 'a'
a1 = 'b'
a3 = 'c'
a4 = 'd'
for i in [0, 1, 3, 4]:
print(eval-'a{}'.format(i)))