这种格式怎么解,有木有现成的库?
Map(2000ZY -> , 602001 -> 31, 202002 -> , 20200I -> 302000, 20200D -> 302000, 602008 -> 0, 20200E -> 16, 202006 -> , 20200j -> 20200j, 20200m -> , 602002 -> 0, 20200a -> , 20200J -> 302000, 20200F -> 302001, 20200n -> 302000, 202007 -> 202007, 202001 -> 202001, 20200l -> 20200l, 602007 -> 0, 202004 -> , 602003 -> 0, 202008 -> , 20200o -> 302000, 2000ZX -> , 20200G -> 0, 20200k -> , 2000ZZ -> , 602004 -> 302000, 202009 -> 202009, 202003 -> 202003, 202005 -> 202005, 20200H -> 302000) ----------------------- 以下是精选回复-----------------------
答:Scala 风格的 Map 写法
答:用 python 怎么解呢,
答:dict(re.findall(r'(\w+)\s*\-\>\s*(\w*)', raw))
答:dict([v.split(' -> ') for v in raw.split(',')])
答:如何将该格式存成 csv ?
答:http://lmgtfy.com/?q=python+csv
答: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)
答:这种都是练手级别的习题啊,直接拿来当面试题就好了。
0条评论