-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maruyama #33
base: master
Are you sure you want to change the base?
Conversation
100本ノック第一章00.
100本ノック第1章01.です
100本ノック第1章03です。
# -*- coding: utf-8 -*- | ||
line_number = 0 | ||
with open('input.txt') as input_file: | ||
for line in input_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line_numberを使うよりもenumerateを使う
for num, line in enumerate(input_file):
# hogehoge
@@ -0,0 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
with open('input.txt') as input_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ネストが多くなるのは、できるだけ避ける
with構文の場合は, 複数の構文も下の様に書ける
with open('file1') as fp1, open('file2') as fp2:
#hogehoge
with open('col1.txt', 'w') as output1_file: | ||
with open('col2.txt', 'w') as output2_file: | ||
for line in iter(input_file.readlines()): | ||
output1_file.writelines(line.split('\t')[0]+'\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3個以上になると \を使って改行しないといけないので ならcontextlib.ExitStackが個人的にはオススメ
ExitStack
あ、あとPR先をmaruyama branchに変えておいてくださいお願いします! |
100本ノック11修正及び13