自分のテキストを読み取り、<h1>…</hi>の行数で区切りその区間でいくつ行数があるか数えるプログラミングを作成したいです。
python
1with open('cotton.txt',encoding="utf-8_sig") as f: 2 lines = f.read().splitlines() 3 4print('\n'.join(lines)) 5print(sum ([1 for _ in open('cotton.txt',encoding="utf-8_sig")]))
結果
<h1>file:1941 55.txt</h1>
the variation of raw cotton con stituents with physical properties
microscopic structure of the cotton fiber
base-combining capacity of cotton
direct processing of whole cotton
shrinkage and cell wall structure of cotton fibers
the hydrolysis and catalytic oxidation of cellulosic materials. iii. the rates of hydrolysis of cotton mercerized with and without tension
surface characteristics of cotton fibers as indicatcd by electro phoretic studies
a comparison of five methods of measuring fineness of cotton fibers
<h1>file:1942 99.txt</h1>
cotton changes color
<h1>file:1943 91.txt</h1>
strength of cotton fiber bundles
tensile strength of cotton fiber
・
・
・
2201
と全体の行数を出すところまではできます。
<h1>file:1941 55.txt</h1>
9
<h1>file:1942 99.txt</h1>
1
<h1>file:1943 91.txt</h1>
2
のようにしたいです!
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー