LoginSignup
0
0

More than 5 years have passed since last update.

ファイル関連(備忘)

Posted at

ファイルの読み書きの備忘

sample.rb
#ファイルの読込
orderSum = {}

with open('input/input.txt', 'r', encoding='utf-8') as f:
    for row in f:
        data = row.rstrip().split(',')
        name = data[0]
        order = data[1]
        if order in orderSum:
            orderSum[order] += 1
        else:
            orderSum[order] = 1

with open('output/output.txt', 'w', encoding='utf-8') as f:
    for key, value in orderSum.items():
        f.write(key + ':' + str(value) + '\n')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0