只需要4行代码就能搞定》》》》》- # -*- coding: utf-8 -*-
- # version: Python 3.7.0
- from collections import defaultdict
- scro = [
- ["demao","GC",123456,"1","张三","SD",12345456644,"XX1","移动电话","非亲属"],
- ["demao","GC",123456,"1","张三","SD",12345456645,"XX2","E-mail","客户"],
- ["demao","GC",123456,"1","张三","SD",12345456646,"XX3","移动电话","非亲属"],
- ["demao","GC",123456,"1","张三","SD",12345456647,"XX4","E-mail","客户"],
- ["demao","GC",123456,"1","张三","SD",12345456648,"XX5","移动电话","非亲属"],
- ["demao","GC",123456,"1","张三","SD",12345456649,"XX6","固定电话","父亲"],
- ["demao","GC",123456,"1","张三","SD",12345456650,"XX7","移动电话","父亲"],
- ["demao","GC",789123,"1","李四","SD",12345456653,"XX10","移动电话","其他亲属"],
- ["demao","GC",789123,"1","李四","SD",12345456654,"XX11","主要手机号码","客户"],
- ["demao","GC",789123,"1","李四","SD",12345456655,"XX12","工作电话","客户"],
- ["demao","GC",789123,"1","李四","SD",12345456656,"XX13","E-mail","客户"],
- ["demao","GC",789123,"1","李四","SD",12345456657,"XX14","固定电话","父亲"],
- ["demao","GC",789123,"1","李四","SD",12345456658,"XX15","验证电话","客户"],
- ["demao","GC",789123,"1","李四","SD",12345456659,"XX16","E-mail","客户"]
- ]
- my_dic = defaultdict(list)
- for i in scro:
- my_dic[tuple(i[:6])] += i[6:]
- my_res = [list(k)+v for k, v in my_dic.items()]
- print(my_res)
复制代码
|