1
CSDreamer 2016-05-30 11:26:57 +08:00 1
Scala 风格的 Map 写法
|
2
ideaplat OP 用 python 怎么解呢,
|
3
yangtukun1412 2016-05-30 11:40:01 +08:00 1
dict(re.findall(r'(\w+)\s*\-\>\s*(\w*)', raw))
|
4
deangl 2016-05-30 11:44:33 +08:00 2
dict([v.split(' -> ') for v in raw.split(',')])
|
5
ideaplat OP 如何将该格式存成 csv ?
|
6
yangtukun1412 2016-05-30 13:11:29 +08:00 1
|
7
ideaplat OP import csv
import json fieldnames = ['rq',' 2000ZZ', ' 2000ZX', ' 202007', ' 202006', ' 202005', ' 202004', ' 202003', ' 202002', ' 202001', ' 202009', ' 202008', ' 20200G', ' 20200F', ' 20200E', ' 20200D', 'Map(2000ZY', ' 20200J', ' 20200I', ' 20200H', ' 602008', ' 602003', ' 602002', ' 602001', ' 602007', ' 602004', ' 20200a', ' 20200o', ' 20200n', ' 20200m', ' 20200l', ' 20200k', ' 20200j'] csv_file = open('0007A8A74A3A.csv', 'wb') writer = csv.DictWriter(csv_file,fieldnames=fieldnames) writer.writeheader() with open("0007A8A74A3A.tsv") as tsv: for line in csv.reader(tsv, dialect="excel-tab"): res = dict([v.split(' -> ') for v in line[5].split(',')]) rq = {'rq':line[1]} res.update(rq) writer.writerow(res) |
8
JamesRuan 2016-05-30 17:39:53 +08:00
这种都是练手级别的习题啊,直接拿来当面试题就好了。
|