# -*- coding: utf-8 -*-
#!/usr/local/bin/python

import pdb
#创建字典

pdb.set_trace()

a = dict.fromkeys(xrange(1000))
b = dict.fromkeys(xrange(500,1000))

#最快计算出并集的方法
union = dict(a,**b)
print union

#最快,最简洁计算出交集的方法
inter = dict.fromkeys([x for x in a if x in b])
print inter


#如果字典a,b 的条目的数目差异很大,那么在for 子句中用较短的那个字典,在if 语句中用较长的那个字典会有利于运算速度的提升。
if len(a) < len(b) :
    inter = dict.fromkeys([x for x in a if x not in b ]) 
else:
    inter = dict.fromkeys([x for x in b if x not in a ]) 
print inter 

#集合的运算,最好还是用set 
a = set(xrange(1000))
b = set(xrange(500,1500))
union = a | b 
inter = a & b 
print union
print inter

#属于a或b ,但却不属于a 和 b 的交集的集合
print