-
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
q13, q14, q15, q16 を解答 #31
base: inaoka
Are you sure you want to change the base?
Changes from 5 commits
48b0892
f528ed9
689b558
625f56e
e7d3872
db9409b
4571fba
898cb3b
443b32e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
高知県 | ||
埼玉県 | ||
岐阜県 | ||
山形県 | ||
山梨県 | ||
和歌山県 | ||
静岡県 | ||
山梨県 | ||
埼玉県 | ||
群馬県 | ||
群馬県 | ||
愛知県 | ||
千葉県 | ||
静岡県 | ||
愛媛県 | ||
山形県 | ||
岐阜県 | ||
群馬県 | ||
千葉県 | ||
埼玉県 | ||
大阪府 | ||
山梨県 | ||
山形県 | ||
愛知県 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
江川崎 | ||
熊谷 | ||
多治見 | ||
山形 | ||
甲府 | ||
かつらぎ | ||
天竜 | ||
勝沼 | ||
越谷 | ||
館林 | ||
上里見 | ||
愛西 | ||
牛久 | ||
佐久間 | ||
宇和島 | ||
酒田 | ||
美濃 | ||
前橋 | ||
茂原 | ||
鳩山 | ||
豊中 | ||
大月 | ||
鶴岡 | ||
名古屋 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# coding: utf-8 | ||
|
||
with open("col1.txt", "r") as col1_f,\ | ||
open("col2.txt", "r") as col2_f,\ | ||
open("col12.txt", "w") as col12_f: | ||
for col1, col2 in zip(col1_f, col2_f): | ||
print("{}\t{}".format(col1.rstrip(), col2.rstrip()), file=col12_f) | ||
# paste col1.txt col2.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# coding:utf-8 | ||
import sys | ||
|
||
args = sys.argv | ||
n = int(args[1]) | ||
path = args[2] | ||
|
||
with open(path, "r") as fin: | ||
for i in range(n): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readlineよりもenumerateとfileのイテレータを活用しよう for idx, line in enumerate(fin):
if idx > n : break
print(line, end='') |
||
line = fin.readline() | ||
if not line: | ||
break | ||
print(line, end="") | ||
# python q14.py 4 col1.txt | ||
# head -n 4 col1.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# coding:utf-8 | ||
|
||
import sys | ||
from collections import deque | ||
|
||
args = sys.argv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これくらい単純なプログラムは There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 外部ライブラリを何かライブラリを使うなら clickってやつがオススメです. |
||
n = int(args[1]) | ||
path = args[2] | ||
|
||
with open(path, "r") as fin: | ||
print(*deque(fin, n), sep="", end="") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このdequeの使い方いいね:+1: |
||
# python q15.py 4 col1.txt | ||
# tail -n 4 col1.txt |
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.
の方がコードが読みやすくなりますね