本帖最后由 pcl_test 于 2016-4-3 21:17 编辑
举个栗子,字典法- # encoding: UTF-8
- from collections import OrderedDict
- stem = OrderedDict([('a','1'), ('b','2'), ('c','3')])
- jd = ['a 2', 'a 3', 'c 1', 'd 4', 'e 5', 'b 6']
- for i in jd:
- t = i.split()
- if stem.get(t[0]):
- stem[t[0]] += '\t' + t[1]
- for i, j in stem.items():
- print(i+'\t'+j)
复制代码
|