dict.items() 返回的是一个元组,对这个元组排序。 也就是 dict ---> 有序的元组。 这样列表中的元素就是有序元组了。可以用 set
HikiJoy
2016-01-09 13:24:13 +08:00
全部转成 JSON
xjoker
2016-01-10 11:16:11 +08:00
set 可以么
Feiox
2016-01-10 12:30:08 +08:00
把每个 dict 包裹进一个对象,设置一定规则取 __hash__ 然后吧这些对象丢进 set 中去并集,然后在取出。。。。
shajiquan
2016-01-10 16:07:45 +08:00
intersection = lambda a, b, c: \ [ \ dict(t) for t in \ set([ \ tuple(da.items()) for da in a if \ tuple(da.items()) in [tuple(db.items()) for db in b] and \ tuple(da.items()) in [tuple(dc.items()) for dc in c] \ ]) \ ]
shajiquan
2016-01-10 16:08:01 +08:00
```python
intersection = lambda a, b, c: \ [ \ dict(t) for t in \ set([ \ tuple(da.items()) for da in a if \ tuple(da.items()) in [tuple(db.items()) for db in b] and \ tuple(da.items()) in [tuple(dc.items()) for dc in c] \ ]) \ ]
```
lixiaohan
2016-01-11 10:28:29 +08:00
a = [.....] b = [......] c = [......] sa = set(tuple(aa.items()) for aa in a) sb = set(tuple(aa.items()) for aa in b) sc = set(tuple(aa.items()) for aa in c)