21 件 見つかりました。
cat WORDS-ASCII_SORTED | xargs -L1 ./look.py > res
while p >= 0: self.f.seek(p) if self.f.read(1) == '\n': break p -= 1
### Python import random if a := int(random.random() * 2): print(f'true [{a}]') else: print(f'false [{a}]')
### Perl use strict; use warnings; if (my $a = int(rand(2))) { print "true [$a]\n"; } else { print "false [$a]\n"; } # 右辺によっては「代入と比較を間違ってませんか」的な warning が出る if (my $a = 1) { print "true [$a]\n"; } else { print "false [$a]\n"; }
0,2,0,こんにちは,50,0,0,0,0,0 1,1,1,さようなら,0,0,0,0,0,0
理想: 1,1,0,"ああ,いい,ううう。",21,0,0,0,0,0 0,2,0,"あれれれ,",50,0,0,0,0,0 現実: 1,1,0,ああ,いい,ううう。,21,0,0,0,0,0 0,2,0,あれれれ,,50,0,0,0,0,0
1,1,0,ああ,いい,ううう。,21,0,0,0,0,0 ↓ カンマで分割してリストにする 1 1 0 ああ いい ううう。 21 0 0 0 0 0 ↓ 前と後ろのカラムを取る [1 1 0] ああ いい ううう。 [21 0 0 0 0 0] ↓ ああ いい ううう。 ↓ 残りをカンマで繋ぎ直し、ダブルクォートで囲む "ああ,いい,ううう。" ↓ さっき取った、前と後ろのカラムと合わせて最終的な CSV にする 1,1,0,"ああ,いい,ううう。",21,0,0,0,0,0
my $IX = 4; # 4番目のカラムがカンマ入りテキスト my $N = 10; # 全部で10カラム while (<>) { chomp; # 末尾の改行削除 my @F = split(",", $_, -1); # 読み込んだ CSV 行をカンマで切ってリストへ my @pre = @F[0..($IX-2)]; # 前から IX-1 個分のカラム my @post = @F[$#F-($N-$IX-1)..$#F]; # 後ろから N-IX 個分のカラム my $text = join(",", @F[($IX-1)..($#F-($N-$IX))]); # カンマ入りテキスト print join(",", @pre, "\"$text\"", @post)."\n"; # CSV に戻す }
my $IX = 4; # 4番目のカラムがカンマ入りテキスト my $N = 4; # 全部で10カラム while (<>) { chomp; # 末尾の改行削除 my @F = split(",", $_, -1); # 読み込んだ CSV 行をカンマで切ってリストへ my @ts = join(",", splice(@F, $IX-1, (@F-$N) + 1)); # テキスト部分の抜き出し splice(@F, $IX-1, 0, qq(").join(",", @ts).qq(")); # ""をつけて戻す print join(",", @F)."\n"; # CSV に戻す }
ID = 4 N = 10 with open('sample.csv') as f: for line in f.read().splitlines(): pre = line.split(",", ID - 1) post = pre[-1].rsplit(",", N - ID) l = pre[:-1] l.append('"' + post[0] + '"') l.extend(post[1:]) print(",".join(l))
1,1,0,ああ,いい,ううう。,21,0,0,0,0,0 ↓ 最初の split で前から4分割(3箇所で切断) 1 / 1 / 0 / ああ,いい,ううう。,21,0,0,0,0,0 ↓ 一番右の塊を次の rsplit で後ろから7分割(6箇所で切断)。 ああ,いい,ううう。 / 21 / 0 / 0 / 0 / 0 / 0 ↓ 1 / 1 / 0 / ああ,いい,ううう。 / 21 / 0 / 0 / 0 / 0 / 0 ↓ 1,1,0,"ああ,いい,ううう。",21,0,0,0,0,0
今はできない。代わりの方法。brew install mongodb
brew tap mongodb/brew brew install mongodb-community cat /usr/local/etc/mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0.0.1
brew services start mongodb-community
sudo yum install -y mongodb-org
sudo systemctl start mongod
mongo use test show dbs db.stats() # db.createCollection('hello') show collections db.hello.stats() db.hello.insert({'uid':123, 'test':'World'}) db.hello.insert({'uid':"oreore", 'text':'This is a pen.'}) db.hello.insert({'uid':"you", 'text':'Today is ...'}) db.hello.find() db.hello.findOne() db.hello.findOne()["uid"] var r = db.hello.find() while (r.hasNext()) printjson(r.next()) quit()
mongodump -d test mongo use test db.hello.drop() db.dropDatabase() show dbs quit() mongorestore ./dump
mongotop mongostat
db.hello.find({}, {uid: 1, text: 1, _id: 0}) db.hello.find({$or: [{'uid':123}, {'uid':"you"}]}, {uid: 1, text: 1, _id: 0}) db.hello.find({$or: [{'uid':123}, {'uid':"you"}, {'uid':"oreore"}]}, {ud: 1, text: 1, _id: 0}) db.hello.find({$or: [{'uid':123}, {'uid':"you"}, {'uid':"NO"}]}, {uid: 1, text: 1, _id: 0})
db.hello.update({"uid" : "you"}, {$set : {"text":"こんにちは"}}) db.hello.insert({'uid':"me", 'hist':[{'ymd':20201020,'val':12}]}) db.hello.update({'uid':"me"}, {$push:{'hist':{'ymd':20201024,'val':38}}}) db.hello.update({'uid':"me"}, {$set:{'last-update':ISODate("2020-10-24T12:55:15")}})
テストスクリプト:pip install pymongo
from pymongo import MongoClient import datetime dt_now = datetime.datetime.now() client = MongoClient('localhost',27017) db = client.test col = db.hello for i in col.find(): print(i) col.update_one({'uid':"me"}, { '$push':{'hist':{'ymd':dt_now,'val':189}}, '$set':{'last-update':dt_now} }) print(col.find_one({'uid':"me"}))
亡くなった人のうち、20代は1人で全体に占める割合は0.3%、30代は1人で0.3%、40代は5人で1.5%、50代は16人で4.9%、60代は32人で9.9%、70代は93人で28.6%、80代は113人で34.8%、90代は61人で18.8%、100歳以上は3人で0.9%でした。
ddf['死亡者数'] = (0,0,0,0,1,9,18,40,38,16,0)
ddf['死亡者数'] = (0,0,1,1,5,16,32,93,113,61,3)