1
jatesun 2017-12-16 08:31:55 +08:00 via iPhone 1
遍历后放入字 list 而不是字符串
|
2
fml87 2017-12-16 09:00:00 +08:00 1
```
from collections import defaultdict d = defaultdict(list) for i in l: d[i['name']].append(i['url']) output = [{"name": i[0], "url": i[1]} for i in d.items()] ``` |
4
imn1 2017-12-16 10:42:34 +08:00
pandas groupby
如果仅仅是输出,就没必要用 pandas 不过如果像这种二维变三维,还有后续计算,可以试试 pandas |
5
codingcrush 2017-12-16 12:22:20 +08:00
from itertools import groupby
print([{k: [item["url"] for item in v]} for k, v in groupby(l, key=lambda item: item["name"])]) |